Skip to content

The values of the traversable enum generate the union type #40691

Closed
@victorykong

Description

@victorykong

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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions