Concept Flow - Distributive conditional types
Start with type T
Is T a union?
Final type
Distributive conditional types check each member of a union type separately, then combine the results.
type Example<T> = T extends string ? "yes" : "no"; type Result = Example<string | number>;
| Step | Type T | Condition (T extends string?) | Result for T | Combined Result |
|---|---|---|---|---|
| 1 | string | string extends string? Yes | "yes" | "yes" |
| 2 | number | number extends string? No | "no" | "yes" | "no" |
| 3 | Final | - | - | "yes" | "no" |
| Variable | Start | After 1 | After 2 | Final |
|---|---|---|---|---|
| T | string | number | string | number | - |
| Result for T | - | "yes" | "no" | "yes" | "no" |
Distributive conditional types split union types and apply conditions to each member. Syntax: T extends U ? X : Y If T is a union, condition applies to each member separately. Results combine into a new union type. If T is not a union, condition applies directly. Useful for transforming union types based on conditions.