Created
May 28, 2020 16:00
-
-
Save gabriel-dehan/2847f5a6077775640ce17e13c8defac4 to your computer and use it in GitHub Desktop.
enumToObject.ts
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
function enumToObject<T extends Record<string, unknown>, V>(enumObject: T, value: V): Record<keyof T, V> { | |
const obj: Partial<Record<keyof T, V>> = {}; | |
Object.keys(enumObject).forEach((key) => { | |
obj[key as keyof T] = value; | |
}); | |
return obj as Record<keyof T, V>; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment