Skip to content

Instantly share code, notes, and snippets.

@slacktracer
Created January 27, 2023 19:37
kinda typing fromEntries result as a enum-ish
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