← TypeScript learning path
TypeScript · Module 4 of 10

Objects, interfaces and type aliases

Describe the shape of objects with interface and type.

📖 Key ideas

  1. interface User { id: number; name: string; email?: string }
  2. type Point = { x: number; y: number }.
  3. readonly makes a property unchangeable.
  4. Interfaces can extend: interface Admin extends User { role: string }.
  5. 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