TypeScript · Middle · Question 23 of 75

What does Extract<'a' | 'b' | 1 | 2, string> produce?

Explanation

Extract<T, U> keeps the union members assignable to U - here, the string literals. The opposite Exclude would keep 1 | 2. Both utilities are distributive conditional types.

Further reading

Problem with a question

TypeScript · Middle · question 23

Test yourself

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

Take this quiz