Created
February 7, 2022 15:48
-
-
Save dagda1/654906fddf07356867328b265403c388 to your computer and use it in GitHub Desktop.
Extend undefined order
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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