Skip to content

Instantly share code, notes, and snippets.

@fzed51
Created September 21, 2024 09:35
Show Gist options
  • Save fzed51/dba5cd39f5678f3eb55bbed994cb2772 to your computer and use it in GitHub Desktop.
Save fzed51/dba5cd39f5678f3eb55bbed994cb2772 to your computer and use it in GitHub Desktop.
[TS] array to enum
export const statusList = [
"enable",
"disable",
] as const;
export type Status = (typeof statusList)[number];
export const Status = Object.fromEntries(statusList.map(v => [v, v])) as {
[K in Status]: K;
};
//
const enable: Status = "enable" // it's OK
const disable = Status.disable // it's OK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment