πŸ‘¨β€πŸ’Ό This is your chance to practice everything you've learned! This single file contains challenges covering all the TypeScript concepts from the workshop.

What You'll Practice

This exercise covers:
  1. Type Aliases & Interfaces - Creating reusable type definitions
  2. Union & Intersection Types - Combining and narrowing types
  3. Literal Types - Preserving specific values with as const
  4. Generics & Constraints - Writing flexible, reusable functions
  5. Discriminated Unions - Modeling complex state with type safety
  6. Any vs Unknown - Working safely with unknown data
  7. Complex Combinations - Putting it all together

Getting Started

🐨 Open
index.ts
and work through each section. Each section has 🐨 instructions explaining what to implement.
πŸ’° Start with the type definitions - they'll help TypeScript guide you as you implement the functions.
πŸ’° Uncomment the "Test Section" snippets at the bottom of each section to smoke-check your work in the console.

What success looks like

There are no automated tests. You're done with a section when:
  1. Type Aliases & Interfaces β€” A Customer value type-checks with required BaseEntity fields, nested Address, and isActive
  2. Union & Intersection Types β€” processPayment narrows on type and returns a distinct descriptive string for card, PayPal, and bank payments
  3. Literal Types β€” orderStatuses uses as const; getStatusLabel('pending') returns 'pending' (and likewise for other keys) using the object as the source of truth
  4. Generics & Constraints β€” getProperty, hasProperty, mergeObjects, and filterByProperty type-check at the call sites in the section comments and produce the expected runtime values
  5. Discriminated Unions β€” handleApiResponse covers loading/success/error with exhaustive checking; getFieldValue returns the field's value for each FormField variant
  6. Any vs Unknown β€” safeParseJson returns an object or null; isStringArray is a type guard that returns true only for string arrays
  7. Complex Combinations β€” A Task value type-checks; updateTaskMetadata returns a new task with updated metadata

Tips

πŸ’° Don't worry about getting everything perfect on the first try. Experiment and learn!
πŸ’° Use TypeScript's error messages to guide you - they'll tell you what's missing or incorrect.
πŸ’° The discriminated union sections are great for practicing exhaustive checking with never.
πŸ’° Generic constraints ensure your functions work correctly with any type that meets the requirements.

No Tests, No Solutions

πŸ“ This is pure practice time! There are no tests or solutions. The goal is to build confidence by applying what you've learned. Try different approaches, make mistakes, and learn from them.

Please set the playground first

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