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

Lessons

  1. 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. 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. 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

Module quiz

1. What is the return type of an async function returning a string?
2. What is the type of the error in catch (error) in strict mode?
3. What does { [K in keyof T]: boolean } build?
4. What does infer U do in T extends (infer U)[] ? U : never?
5. What does a branded type such as string & { __brand: 'Email' } prevent?
6. What does 'make invalid states unrepresentable' mean?

‹ Generic codeFinal assessment ›