Combining Types
Combining Types
π¨βπΌ Let's use intersection types to compose complex types from simpler building
blocks.
π¨ Open
and:
- Create base types with these runtime field types:
WithIdβid(string)WithTimestampsβcreatedAtandupdatedAt(Date)WithAuthorβauthorIdandauthorName(string)
- Build entity types by intersecting those bases (and adding entity-specific
fields):
Userβ id + timestamps, plusnameandemail(string)Postβ id + timestamps + author, plustitleandcontent(string)Commentβ id + timestamps + author, plustextandpostId(string)
- Create sample
user,post, andcommentvalues and export them by name
Completion criteria
- Named exports:
user,post,comment userhas stringid/name/emailandDatecreatedAt/updatedAtpost/commentalso include author fields (authorId,authorName) and their own content fields (title/contentortext/postId)