Advanced types and real programs
Mapped, conditional and template literal types, typed async code, and designing programs where invalid states cannot be written.
About 4 hours of study
Learning objectives
- Read and write mapped and conditional types
- Type promises and handle errors
- Design with Result types, brands and discriminated unions
Lessons
- 1
Mapped, conditional and template literal types Advanced
Types that compute other types: keyof and indexed access, mapped types over an object's keys, key remapping, conditional types with infer, and template literal types.
- 2
Async code with types Advanced
Promise<T> and async functions, typing results of Promise.all and Promise.allSettled, errors in catch as unknown, and modelling success and failure with a Result type.
- 3
Designing type-safe programs Advanced
Putting the course together: parse at the edges and trust types inside, make invalid states unrepresentable with discriminated unions, branded types for values that look alike, readonly data, Result types and exhaustive checks.
Module practice
- TypeScript: Form errors with a mapped typeEasy
- TypeScript: Event handlers named by template literal typesMedium
- TypeScript: Parse rows by a schema with conditional typesHard
- TypeScript: Tasks running at the same timeEasy
- TypeScript: Retry with a Result typeMedium
- TypeScript: A pool of async workersHard
- TypeScript: Parse money amounts with a ResultEasy
- TypeScript: Branded ids for users and ordersMedium
- TypeScript: A type-safe ledgerHard