← TypeScript learning pathTypeScript · Module 4 of 10
Objects, interfaces and type aliases
Describe the shape of objects with interface and type.
📖 Key ideas
- interface User { id: number; name: string; email?: string }
- type Point = { x: number; y: number }.
- readonly makes a property unchangeable.
- Interfaces can extend: interface Admin extends User { role: string }.
- Index signatures: { [key: string]: number }.
💡 Real-life example: An interface is a form template: every filled copy must have the same fields.
interfaceNamed object shape
type aliasName for any type
readonlyProperty cannot be reassigned
extendsBuilds on another interface