Skip to content

Instantly share code, notes, and snippets.

@HelveticaScenario
Created March 12, 2020 23:16
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 HelveticaScenario/e01afe288ad9a598863d516ca3bf7de8 to your computer and use it in GitHub Desktop.
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
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