Mastering TypeScript in 2025: Functions, Types & Advanced Features
Author: Kawser Ferdous Safi | Full Stack Developer (MERN Stack) Published: May 1, 2025
🚀 Why TypeScript Still Dominates in 2025
TypeScript isn’t just a superset of JavaScript anymore—it’s the de facto standard for large-scale, maintainable applications. With better IDE support, built-in documentation through types, and unmatched scalability, TypeScript has become a must-have skill for developers in 2025.
This article will walk you through the most important TypeScript features, including:
- Typed Functions (Regular, Arrow, and Methods)
- Type Aliases
- Union & Intersection Types
- Optional Chaining and Nullish Coalescing
- Interfaces vs Type Aliases
- Enums
- Generics
- Utility Types like
Partial<T>
,Pick<T, K>
,Readonly<T>
- Mapped Types
- Advanced Concepts like Asynchronous Programming, Constraints, and Utility Types
Let’s break it all down.
🔧 Functions in TypeScript
✅ Standard Function with Types
1function add(a: number, b: number): number { 2 return a + b; 3} 4console.log(add(2, 3)); // 5
🏹 Arrow Function with Default Params
1const multiply = (a: number, b: number = 2): number => a * b; 2console.log(multiply(5)); // 10 3console.log(multiply(5, 3)); // 15
🧠 Object Method Example
1const user = { 2 name: 'Safi', 3 balance: 1000, 4 addBalance(amount: number): string { 5 return `Updated balance: ${this.balance + amount}`; 6 }, 7}; 8console.log(user.addBalance(500)); // Updated balance: 1500
🧱 Type Aliases for Reusability
1type Student = { 2 name: string; 3 age: number; 4 gender: string; 5 address: string; 6 contactNo?: string; 7}; 8 9const student1: Student = { 10 name: 'Aisha', 11 age: 21, 12 gender: 'female', 13 address: 'Dhaka', 14};
⚙️ Union & Intersection Types
🔀 Union Types
1type Role = 'junior' | 'mid' | 'senior'; 2const devLevel: Role = 'mid'; 3 4type Developer = Role | 'fullstack'; 5const fullDev: Developer = 'fullstack';
➕ Intersection Types
1type FrontEnd = { skills: string[]; designation1: 'FrontEndDeveloper' }; 2type BackEnd = { skills: string[]; designation2: 'BackEndDeveloper' }; 3 4type FullStack = FrontEnd & BackEnd; 5 6const engineer: FullStack = { 7 skills: ['React', 'Node.js'], 8 designation1: 'FrontEndDeveloper', 9 designation2: 'BackEndDeveloper', 10};
🧩 Interfaces vs Type Aliases
Interfaces are used to define contracts in your code and are extendable.
1interface Person { 2 name: string; 3 age: number; 4} 5 6interface Employee extends Person { 7 role: string; 8} 9 10const emp: Employee = { 11 name: 'Kawser', 12 age: 25, 13 role: 'Developer', 14};
🎯 Enums for Fixed Sets
Enums help group constants together.
1enum Direction { 2 Up = 'UP', 3 Down = 'DOWN', 4 Left = 'LEFT', 5 Right = 'RIGHT', 6} 7 8const move = (dir: Direction) => { 9 console.log(`Moving ${dir}`); 10}; 11move(Direction.Left); // Moving LEFT
🧠 Generics for Flexibility
Generics make components and functions reusable for multiple types.
1function identity<T>(value: T): T { 2 return value; 3} 4 5console.log(identity<string>('Hello')); 6console.log(identity<number>(42));
Generic Interfaces
1interface ApiResponse<T> { 2 status: number; 3 data: T; 4} 5 6const response: ApiResponse<string> = { 7 status: 200, 8 data: 'Success', 9};
🛠️ Utility Types
Partial<T>
Make all properties optional.
1interface User { 2 name: string; 3 email: string; 4} 5 6const updateUser = (user: Partial<User>) => { 7 console.log(user); 8}; 9updateUser({ name: 'NewName' });
Pick<T, K>
Pick selected properties.
1type ContactInfo = Pick<User, 'email'>;
Readonly<T>
Make all properties immutable.
1const settings: Readonly<User> = { 2 name: 'Admin', 3 email: 'admin@example.com', 4}; 5// settings.name = 'User'; ❌ Error
🌟 Advanced Syntax
❓ Optional Chaining
1const user = { name: 'Safi', address: { city: 'Dhaka' } }; 2const city = user?.address?.city ?? 'Unknown'; 3console.log(city); // Dhaka
🔄 Nullish Coalescing
1const name = null; 2const displayName = name ?? 'Guest'; 3console.log(displayName); // Guest
✅ Final Thoughts
To become a confident TypeScript developer in 2025, make sure you master:
- Typing Functions and Methods
- Type Aliases and Interfaces
- Union and Intersection Types
- Generics and Enums
- Utility Types and Modern Operators
TypeScript is your gateway to writing robust, clean, and scalable applications with confidence.
💡 Keep Building
The journey doesn’t stop here—explore advanced topics like declaration merging, type guards, mapped types, and inference for deeper control. Your future self will thank you.
- Kawser Ferdous Safi