TypeScript · Middle · Question 51 of 75

Why does Omit<Circle | Square, 'id'> lose the discriminated union?

type DistributiveOmit<T, K extends PropertyKey> = T extends any ? Omit<T, K> : never;

Explanation

keyof (A | B) contains only shared keys, so member-specific properties disappear. The conditional type distributes over the union.

Further reading

Problem with a question

TypeScript · Middle · question 51

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