Skip to content

Instantly share code, notes, and snippets.

@dagda1
Created February 7, 2022 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dagda1/654906fddf07356867328b265403c388 to your computer and use it in GitHub Desktop.
Save dagda1/654906fddf07356867328b265403c388 to your computer and use it in GitHub Desktop.
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