TypeScript · Senior · Question 3 of 75

What is ToArray<string | number> if type ToArray<T> = T extends any ? T[] : never?

Explanation

A conditional type over a "naked" type parameter distributes over a union: the condition is applied to each member separately. This is a distributive conditional type - Exclude and Extract are built on it.

Further reading

Problem with a question

TypeScript · Senior · question 3

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