Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Extend undefined order
type BadUndefinedKeys<T> = {
[P in keyof T]-?: T[P] extends undefined ? P : never
}[keyof T];
type Bad = BadUndefinedKeys<{ foo: number, bar?: string}>; // never
type GoodUndefinedKeys<T> = {
[P in keyof T]-?: undefined extends T[P] ? P : never;
}[keyof T];
type Good = GoodUndefinedKeys<{ foo: number, bar?: string}>; // bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment