Created
February 20, 2021 10:43
-
-
Save kpratik2015/57be2cce2bb4fef3b6e8fbf566a4672a to your computer and use it in GitHub Desktop.
Powerful alternative to enum in typescript
This file contains hidden or 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
/* | |
{ | |
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