Distributive Conditional Types
Understand how conditionals distribute over union members.
Welcome
Distributive conditional types apply a conditional type to each member of a union separately. This powerful behavior enables union transformation and filtering.
What Is Distribution
When a conditional type has a bare generic T and T is a union, TypeScript applies the conditional to each union member separately.
type Wrap<T> = T extends any ? { value: T } : never;
type R = Wrap<string | number>;
// = { value: string } | { value: number }All lessons in this course
- keyof and Indexed Access Types
- Generic Constraints: Narrowing Type Parameters
- Conditional Types: T extends U ? X : Y
- Distributive Conditional Types