Skip to content
webtype.orgTwelve concepts

Twelve concepts

The climb from mapped types to recursive conditional types. Work through these and Friday’s puzzle stops being frightening.

  1. 01

    Type aliases

    A name for a type. Everything else here is an alias that takes arguments.

  2. 02

    Generic parameters

    Aliases take arguments. `extends` in this position is a constraint, not inheritance.

  3. 03

    keyof and indexed access

    `keyof T` is the union of T’s keys; `T[K]` reads a property type back out.

  4. 04

    Mapped types

    Build an object by iterating a union of keys: `{ [K in Keys]: Value }`.

    Practiced in#212 Rebuild Pick#219 Rebuild Partial

  5. 05

    Modifiers

    Add or strip `readonly` and `?` while mapping, with `+` and `-`.

  6. 06

    Conditional types

    `A extends B ? X : Y` — the type-level `if`, asking about assignability.

  7. 07

    infer

    Bind a type variable inside a pattern and use it in the true branch.

    Practiced in#213 Unwrap

  8. 08

    Distributivity

    A naked type parameter in a conditional distributes over unions. `[T]` stops it.

  9. 09

    Template literal types

    String patterns at the type level. Combined with `infer`, they parse.

    Practiced in#214 Route Params#217 Split

  10. 10

    Recursion

    A conditional type that calls itself. The false branch is the exit.

    Practiced in#215 Deep Readonly

  11. 11

    Variadic tuples

    Spread tuples into tuples. `length` turns them into a counter.

    Practiced in#216 Type-level Add#218 Last

  12. 12

    Exact equality

    Why `Equal<X, Y>` is not `extends`, and why an intersection fails it.