Type alias: type Point = { x: number; y: number };
Interface: interface User { name: string; age: number }
Interfaces can be extended: interface Admin extends User { role: string }
Both work for object shapes; type aliases can also name unions and primitives.
💡 Key Takeaways: TypeScript Type Aliases & Interfaces
Mastering TypeScript Type Aliases & Interfaces helps you write clean and reliable TypeScript code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
TypeScript Type Aliases & Interfaces Code Example
TypeScript
type Point = { x: number; y: number };
interface User {
name: string;
age: number;
}
interface Admin extends User {
role: string;
}
const p: Point = { x: 3, y: 4 };
const admin: Admin = { name: "Ayesha", age: 30, role: "owner" };
console.log(p.x + p.y, admin.name, admin.role);
Output
7 Ayesha owner
Free sign-in required · Google login available
TypeScript Type Aliases & Interfaces Practice Exercises
Check what you learned in “TypeScript Type Aliases & Interfaces”.
/ 3 solved
Fill in the blank
Declare an interface.
User { name: string; age: number }
✓ Correct!Not quite. Try again.
Multiple choice
How do you extend an interface?
✓ Correct!Not quite. Try again.
Code challenge
Define interface Student { name: string; grade: number }, create one for "Sara" with grade 92 and log "Sara: 92".
Write the code in the live editor. Your answer is checked automatically.