TypeScript's built-in Omit utility type breaks discriminated unions by treating them as a whole rather than distributing over each union member. This causes type errors when building wrapper components that depend on discriminated union props. A distributive version using conditional types (T extends any ? Omit<T, K> : never) preserves the union structure by applying Omit to each member individually. This solution also provides stricter type checking by constraining keys to those that actually exist on the type.

7m read timeFrom tkdodo.eu
Post cover image
Table of contents
Discriminated Union TypesDistributive Conditional TypesDistributive OmitLimited Keys

Sort: