TypeScript · Senior · Question 4 of 75
How do you turn off a conditional type's distribution over a union?
- ✓Correct answer: Wrap both sides in a tuple:
[T] extends [U] ? X : Y - 2Add the
distributive: falseoption tocompilerOptions - 3Use
infer Uinstead ofextendsin the check
Explanation
Distribution happens only when the checked type is a "naked" parameter. The tuple [T] makes it composite, so the union is checked as a whole: [string | number] extends [string] → false. There's no compiler setting for this.