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 type aliases for IDs, timestamps, and emails
  2. Create User and Post types that use these building blocks
  3. Create userSample and postSample values and export them (tests will import them by name)
πŸ’° Compose larger types from your primitive aliases.

Please set the playground first

Loading "Type Composition"
Loading "Type Composition"
Login to get access to the exclusive discord channel.
Loading Discord Posts