Created
March 12, 2020 23:16
-
-
Save HelveticaScenario/e01afe288ad9a598863d516ca3bf7de8 to your computer and use it in GitHub Desktop.
A type alias for getting a union of keys of an interface that match a type
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 MapKeys<R, T> = { | |
[P in keyof R]: R[P] extends T ? P : never; | |
}; | |
type KeysOfType<R, T, IncludeOptional extends boolean = true> = Exclude< | |
MapKeys<R, IncludeOptional extends true ? T | undefined : T>[keyof R], | |
undefined | |
>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment