Twelve concepts
The climb from mapped types to recursive conditional types. Work through these and Friday’s puzzle stops being frightening.
- 01
Type aliases
A name for a type. Everything else here is an alias that takes arguments.
- 02
Generic parameters
Aliases take arguments. `extends` in this position is a constraint, not inheritance.
- 03
keyof and indexed access
`keyof T` is the union of T’s keys; `T[K]` reads a property type back out.
- 04
Mapped types
Build an object by iterating a union of keys: `{ [K in Keys]: Value }`.
Practiced in#212 Rebuild Pick#219 Rebuild Partial
- 05
Modifiers
Add or strip `readonly` and `?` while mapping, with `+` and `-`.
- 06
Conditional types
`A extends B ? X : Y` — the type-level `if`, asking about assignability.
- 07
- 08
Distributivity
A naked type parameter in a conditional distributes over unions. `[T]` stops it.
- 09
Template literal types
String patterns at the type level. Combined with `infer`, they parse.
Practiced in#214 Route Params#217 Split
- 10
Recursion
A conditional type that calls itself. The false branch is the exit.
Practiced in#215 Deep Readonly
- 11
Variadic tuples
Spread tuples into tuples. `length` turns them into a counter.
Practiced in#216 Type-level Add#218 Last
- 12
Exact equality
Why `Equal<X, Y>` is not `extends`, and why an intersection fails it.