Created
January 27, 2023 19:37
-
-
Save slacktracer/ec1d532cafb62f712025b4ee8a99b5c9 to your computer and use it in GitHub Desktop.
kinda typing fromEntries result as a enum-ish
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
type Keys<T extends readonly string[]> = Readonly<{ [key in T[number]]: key }>; | |
// const keys = ["feat1", "feat2"] as const; | |
export const makeEnumLikeFromArray = <T extends readonly string[]>(array: T) => | |
Object.fromEntries(array.map((item) => [item, item])) as Keys<T>; | |
// const a = make<typeof keys>(keys); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment