Skip to content

Instantly share code, notes, and snippets.

@kpratik2015
Created February 20, 2021 10:43
Show Gist options
  • Save kpratik2015/57be2cce2bb4fef3b6e8fbf566a4672a to your computer and use it in GitHub Desktop.
Save kpratik2015/57be2cce2bb4fef3b6e8fbf566a4672a to your computer and use it in GitHub Desktop.
Powerful alternative to enum in typescript
/*
{
readonly INPUT_CHANGE: "INPUT_CHANGE";
readonly ERROR: "ERROR";
readonly DELETE_ERROR: "DELETE_ERROR";
}
*/
const FormReducerTypes = {
INPUT_CHANGE: "INPUT_CHANGE",
ERROR: "ERROR",
DELETE_ERROR: "DELETE_ERROR",
} as const;
type TFormReducerTypes = typeof FormReducerTypes[keyof typeof FormReducerTypes]; // "INPUT_CHANGE" | "ERROR" | "DELETE_ERROR"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment