TypeScript · Senior · Question 4 of 75

How do you turn off a conditional type's distribution over a union?

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.

Further reading

Problem with a question

TypeScript · Senior · question 4

Test yourself

Take the TypeScript · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz