ruk·si

🏷️ TypeScript
Enums

Updated at 2024-08-02 06:22

Enum indexing starts from 0 by default, but you should use custom integers or strings.

enum Color {Red, Green, Blue}
const c: Color = Color.Green;

Enums are more concise when you need to define a set of named constants.

Enum-like objects are acceptable but they look a bit unaesthetic.

type StatusCodeValue = (typeof StatusCodes)[keyof typeof StatusCodes];

Sources

  • Learning TypeScript by Josh Goldberg