π¨βπΌ 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:
- Type Aliases & Interfaces - Creating reusable type definitions
- Union & Intersection Types - Combining and narrowing types
- Literal Types - Preserving specific values with
as const - Generics & Constraints - Writing flexible, reusable functions
- Discriminated Unions - Modeling complex state with type safety
- Any vs Unknown - Working safely with unknown data
- Complex Combinations - Putting it all together
Getting Started
π¨ Open
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.
π° Use the test code at the bottom to verify your implementations work correctly.
Structure
The file is organized into sections. Work through them in order:
- Type Aliases & Interfaces - Build the foundation
- Union & Intersection Types - Combine types safely
- Literal Types - Create single sources of truth
- Generics & Constraints - Write reusable code
- Discriminated Unions - Model complex state
- Any vs Unknown - Handle unknown data safely
- Complex Combinations - Apply everything together
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.