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