Advanced types
This part builds types from other types: discriminated unions, intersections, mapped and conditional types, infer, template literal types, keyof and typeof, the built-in utility types, and the satisfies and as const forms that keep a literal type.
5.1
Discriminated unions
one-of-many shapes with a shared literal tag, narrowed with a switch
Open
5.2
Intersections
combine object types with & and mix shared behaviour into a value
Open
5.3
Mapped types
build a new object type by mapping over the keys of an old one
Open
5.4
Conditional types
choose between two types with a condition that distributes over a union
Open
5.5
infer
capture a hidden type inside a conditional with infer
Open
5.6
Template literal types
string types built from a pattern, and the checks they make possible
Open
5.7
keyof and typeof
derive a key union with keyof and a type from a value with typeof
Open
5.8
Utility types
Partial, Pick, Omit and the other built-in types that reshape an object
Open
5.9
satisfies
check a shape without widening the literals inside it
Open
5.10
const assertions
as const freezes a value into its literal type, and what that buys
Open