TypeScript Mini Projects
Apply your TypeScript knowledge by building small applications. Practise interfaces, arrays, functions, classes, conditions, and data processing through practical project examples.
Explore Projects →1. Why Build Mini Projects?
Mini projects combine multiple programming concepts into a single application. They help learners understand how code is organized, how data is processed, and how individual functions work together to solve a problem.
Apply Concepts
Combine types, functions, arrays, and objects.
Solve Problems
Turn a requirement into working program logic.
Test Your Code
Check results using different inputs and edge cases.
Build Confidence
Prepare for larger applications and technical interviews.
2. Mini Projects in This Tutorial
Begin with simple logic and progress toward projects that manage structured data.
To-Do List
Add tasks, mark tasks completed, and remove tasks.
Calculator
Perform arithmetic operations and handle invalid operations.
Student Management
Add students, search records, and calculate average marks.
Expense Tracker
Record expenses, categorize them, and calculate totals.
3. To-Do List Application
A To-Do List keeps track of tasks and whether they have been completed. This project introduces interfaces, arrays, searching, updating records, and removing items.
Features
- Add a new task.
- Mark a task as completed.
- Remove a task by ID.
- Display all tasks.
TypeScript Code
interface Task {
id: number;
title: string;
completed: boolean;
}
class TodoList {
private tasks: Task[] = [];
private nextId = 1;
addTask(title: string): void {
const trimmedTitle = title.trim();
if (trimmedTitle === "") {
console.log("Task title is required.");
return;
}
this.tasks.push({
id: this.nextId++,
title: trimmedTitle,
completed: false
});
}
completeTask(id: number): boolean {
const task = this.tasks.find(
task => task.id === id
);
if (!task) {
return false;
}
task.completed = true;
return true;
}
removeTask(id: number): boolean {
const index = this.tasks.findIndex(
task => task.id === id
);
if (index === -1) {
return false;
}
this.tasks.splice(index, 1);
return true;
}
displayTasks(): void {
if (this.tasks.length === 0) {
console.log("No tasks available.");
return;
}
this.tasks.forEach(task => {
const status = task.completed
? "Completed"
: "Pending";
console.log(
task.id + ". " + task.title + " - " + status
);
});
}
}
const todo = new TodoList();
todo.addTask("Learn TypeScript");
todo.addTask("Practise interfaces");
todo.completeTask(1);
todo.displayTasks();
Expected Output
1. Learn TypeScript - Completed
2. Practise interfaces - Pending
Student Practice
Add a method that returns only pending tasks and another method that counts how many tasks have been completed.
4. Simple Calculator
A calculator accepts two numbers and an operation. It then returns the calculated result. This project demonstrates functions, union types, conditions, and error handling.
Features
- Addition and subtraction.
- Multiplication and division.
- Validate division by zero.
- Reject unsupported operations.
TypeScript Code
type Operation = "+" | "-" | "*" | "/";
function calculate(
firstNumber: number,
secondNumber: number,
operation: Operation
): number {
switch (operation) {
case "+":
return firstNumber + secondNumber;
case "-":
return firstNumber - secondNumber;
case "*":
return firstNumber * secondNumber;
case "/":
if (secondNumber === 0) {
throw new Error("Cannot divide by zero.");
}
return firstNumber / secondNumber;
}
}
try {
console.log("Addition: " + calculate(20, 10, "+"));
console.log("Subtraction: " + calculate(20, 10, "-"));
console.log("Multiplication: " + calculate(20, 10, "*"));
console.log("Division: " + calculate(20, 10, "/"));
}
catch (error: unknown) {
if (error instanceof Error) {
console.log("Error: " + error.message);
}
}
Expected Output
Addition: 30
Subtraction: 10
Multiplication: 200
Division: 2
Student Practice
Extend the calculator with a percentage operation and validate the numbers before performing calculations.
5. Student Management System
This mini project stores student records in an array. You can add students, search by ID, and calculate the average marks of a student.
Features
- Add student records.
- Search for a student by ID.
- Calculate average marks.
- Handle missing student records.
TypeScript Code
interface Student {
id: number;
name: string;
marks: number[];
}
class StudentManagement {
private students: Student[] = [];
addStudent(student: Student): void {
const exists = this.students.some(
item => item.id === student.id
);
if (exists) {
throw new Error("Student ID already exists.");
}
this.students.push(student);
}
findStudent(id: number): Student | undefined {
return this.students.find(
student => student.id === id
);
}
calculateAverage(id: number): number | undefined {
const student = this.findStudent(id);
if (!student || student.marks.length === 0) {
return undefined;
}
const total = student.marks.reduce(
(sum, mark) => sum + mark,
0
);
return total / student.marks.length;
}
}
const management = new StudentManagement();
management.addStudent({
id: 101,
name: "Rahul",
marks: [80, 90, 85]
});
const student = management.findStudent(101);
if (student) {
console.log("Name: " + student.name);
console.log(
"Average: " + management.calculateAverage(101)
);
}
Expected Output
Name: Rahul
Average: 85
Student Practice
Add methods to display all student records, update marks, and remove a student by ID.
6. Expense Tracker
An Expense Tracker records spending and calculates the total amount spent. This example demonstrates arrays of objects, filtering by category, and aggregating numerical values.
Features
- Record expense details.
- Calculate total expenses.
- Filter expenses by category.
- Calculate expenses by category.
TypeScript Code
type ExpenseCategory =
| "Food"
| "Travel"
| "Education"
| "Other";
interface Expense {
id: number;
title: string;
amount: number;
category: ExpenseCategory;
}
const expenses: Expense[] = [
{
id: 1,
title: "Lunch",
amount: 200,
category: "Food"
},
{
id: 2,
title: "Bus Ticket",
amount: 100,
category: "Travel"
},
{
id: 3,
title: "Course Book",
amount: 500,
category: "Education"
},
{
id: 4,
title: "Dinner",
amount: 300,
category: "Food"
}
];
function calculateTotal(items: Expense[]): number {
return items.reduce(
(total, expense) => total + expense.amount,
0
);
}
function calculateByCategory(
category: ExpenseCategory
): number {
const filteredExpenses = expenses.filter(
expense => expense.category === category
);
return calculateTotal(filteredExpenses);
}
console.log("Total Expenses: Rs. " + calculateTotal(expenses));
console.log("Food Expenses: Rs. " + calculateByCategory("Food"));
console.log("Travel Expenses: Rs. " + calculateByCategory("Travel"));
Expected Output
Total Expenses: Rs. 1100
Food Expenses: Rs. 500
Travel Expenses: Rs. 100
Student Practice
Add functionality to find the highest expense and display all expenses above a user-defined amount.
7. Mini Project Comparison
| Project | Main Concepts | Suggested Level |
|---|---|---|
| To-Do List | Interfaces, arrays, classes, CRUD-like operations | Beginner |
| Calculator | Functions, union types, conditions, error handling | Beginner |
| Student Management | Interfaces, classes, searching, aggregation | Beginner to Intermediate |
| Expense Tracker | Object arrays, filtering, aggregation, categories | Beginner to Intermediate |
8. How to Build These Projects
Step 1: Understand Requirements
List the operations the application needs to support.
Step 2: Define Types
Create interfaces and types for your data.
Step 3: Implement Logic
Write small, reusable functions and classes.
Step 4: Test Results
Test normal inputs, empty values, missing IDs, and invalid operations.
Summary
- The To-Do List practises task management and array operations.
- The Calculator practises functions, conditions, and error handling.
- The Student Management project practises interfaces and classes.
- The Expense Tracker practises filtering and numerical aggregation.
- Mini projects combine multiple TypeScript concepts into useful programs.
- Testing invalid and boundary inputs makes your applications more reliable.