Type Composition

Composition
πŸ‘¨β€πŸ’Ό Type aliases can reference other type aliases, letting you build complex types from simpler ones. This creates a vocabulary for your domain.
type Name = string
type Age = number
type User = { name: Name; age: Age }
Using type aliases for primitives adds semantic meaning. Instead of seeing string everywhere, you see Email, ID, or Timestampβ€”making code self-documenting.
🐨 Open
index.ts
and:
  1. Create primitive aliases ID (string), Timestamp (number), and Email (string)
  2. Create a User type that uses those primitives for id, createdAt, updatedAt, and email, plus a name: string field
  3. Create a Post type that uses those primitives for id, createdAt, updatedAt, and authorId, plus title and content string fields
  4. Create userSample and postSample values that match those types and export them by name

Completion criteria

  • Named exports: userSample, postSample
  • userSample has string id / name / email and number createdAt / updatedAt
  • postSample has string id / title / content / authorId and number createdAt / updatedAt
πŸ’° Compose larger types from your primitive aliases.

Please set the playground first

Loading "Type Composition"
Loading "Type Composition"