distributive conditional type
A conditional type on a bare type parameter, which is applied separately to each member of a union and the results combined.
In more detail
If T is the union A | B, the condition is checked once for A and once for B, and the two answers are joined into a union again. This is how Exclude filters unions. Wrapping both sides in brackets, [T] extends [U], turns distribution off.
Related terms
- conditional type — A type that picks one of two types depending on whether a type is assignable to another, written like a ternary expression with extends.
- Exclude<T, U> — The utility type that removes from union T every member assignable to U, such as Exclude<HttpMethod, "GET">.
- union type — A type that allows one of several listed types or values, written with a vertical bar, such as int | None in Python or "small" | "large" in TypeScript.
Taught in
- Verify Your Environment: Running tsc And Bun TypeScript — Production TypeScript
- Conditional Types: Ternary Types And Type Inference With infer — Production TypeScript