A free, self-paced textbook in 7 chapters. Read a chapter, then drill it with the 241 companion flashcards using spaced repetition.
A generic in TypeScript is a placeholder for a type that is filled in at the call site, letting a single function, class, or interface operate over many types while preserving the...
TypeScript ships a rich set of utility types that compose new shapes from existing ones. The companions of Partial<T> are Required<T>—implemented as { [K in keyof T]-?:...
A conditional type has the shape T extends U ? A : B and is evaluated at the type level: if the source type is assignable to the target, you get A; otherwise B. The most consequent...
A mapped type walks the keys of an existing type and produces a new one, in the form { [K in keyof T]: ... }. The built-ins Partial<T>, Required<T>, and Readonly<T&g...
TypeScript narrows a value's type within control-flow branches using predicates and operators. A user-defined type guard has the form function isString(x: unknown): x is string { r...
Tuples let generic types represent fixed-shape arrays precisely, and TypeScript extends this idea with variadic tuple types—tuples containing rest elements like [string, ...number[...
Several language features elevate generics from "type-safe containers" into full API design tools. The satisfies operator validates that a value conforms to a shape without forcing...
← Back to the Typescript Generics Patterns And Constraints deck