Created
January 27, 2023 19:37
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