Created
February 24, 2023 15:27
-
-
Save bradyclifford/d1d5bcd49287f5a795e150798f8b5fcf to your computer and use it in GitHub Desktop.
Lookup Typescript String Enum by key
This file contains 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
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