Combining Types

Combining Types
πŸ‘¨β€πŸ’Ό Let's use intersection types to compose complex types from simpler building blocks.
🐨 Open
index.ts
and:
  1. Create base types with these runtime field types:
    • WithId β€” id (string)
    • WithTimestamps β€” createdAt and updatedAt (Date)
    • WithAuthor β€” authorId and authorName (string)
  2. Build entity types by intersecting those bases (and adding entity-specific fields):
    • User β€” id + timestamps, plus name and email (string)
    • Post β€” id + timestamps + author, plus title and content (string)
    • Comment β€” id + timestamps + author, plus text and postId (string)
  3. Create sample user, post, and comment values and export them by name

Completion criteria

  • Named exports: user, post, comment
  • user has string id / name / email and Date createdAt / updatedAt
  • post / comment also include author fields (authorId, authorName) and their own content fields (title/content or text/postId)

Please set the playground first

Loading "Combining Types"
Loading "Combining Types"