Skip to content

Instantly share code, notes, and snippets.

@bradyclifford
Created February 24, 2023 15:27
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 bradyclifford/d1d5bcd49287f5a795e150798f8b5fcf to your computer and use it in GitHub Desktop.
Save bradyclifford/d1d5bcd49287f5a795e150798f8b5fcf to your computer and use it in GitHub Desktop.
Lookup Typescript String Enum by key
export function getEnumValueLookup<T extends Record<keyof T, string>>(object: T) {
return Object.fromEntries(
Object.entries(object).map(([key, value]) => [value as string, key as keyof T])
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment