Created
July 12, 2022 09:10
-
-
Save ikasoba/ba4981cead4c1d3418a9789f85f46663 to your computer and use it in GitHub Desktop.
create enum like object from string[]
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
| const createEnum = <T extends string|number>(a:readonly T[]|T[]): {[K in T]: K} => Object.fromEntries<T>(a.map(x => [x,x])) as any; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment