Closed
Description
Search Terms
enum
keyof
typeof
Use Cases
type num = VALUE.ZERO | VALUE.ONE | VALUE.TWO;
const number0: num = 0;
const number1: num = 1;
const number2: num = 2;
const number3: num = 3; // Success??
Examples
How do I define a type constraint in my enumeration value?
enum VALUE {
ZERO,
ONE,
TWO,
}
type KEY = keyof typeof VALUE; // "ZERO" | "ONE" | "TWO"