Interfaces and Type Aliases
Purpose: model real data shapes. Benefit: your objects become predictable and self-documented.
David Miller
December 21, 2025
0.0k0
Interfaces and types describe object shapes. ## Interface ```ts interface User { id: number; name: string; active: boolean; } ``` Use it: ```ts const user: User = { id: 1, name: "Tom", active: true, }; ``` ## Type alias ```ts type Product = { id: number; price: number; }; ``` ## Differences (simple) - interface: extendable, good for objects - type: flexible, unions, primitives ## Union types ```ts type ID = number | string; let uid: ID = 10; uid = "A10"; ``` ## Remember - interfaces for object contracts - type for flexible compositions
#TypeScript#Beginner#Interfaces