π¨βπΌ 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.
π° 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:
- Type Aliases & Interfaces β A
Customervalue type-checks with requiredBaseEntityfields, nestedAddress, andisActive - Union & Intersection Types β
processPaymentnarrows ontypeand returns a distinct descriptive string for card, PayPal, and bank payments - Literal Types β
orderStatusesusesas const;getStatusLabel('pending')returns'pending'(and likewise for other keys) using the object as the source of truth - Generics & Constraints β
getProperty,hasProperty,mergeObjects, andfilterByPropertytype-check at the call sites in the section comments and produce the expected runtime values - Discriminated Unions β
handleApiResponsecovers loading/success/error with exhaustive checking;getFieldValuereturns the field's value for eachFormFieldvariant - Any vs Unknown β
safeParseJsonreturns an object ornull;isStringArrayis a type guard that returnstrueonly for string arrays - Complex Combinations β A
Taskvalue type-checks;updateTaskMetadatareturns a new task with updatedmetadata
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.