Skip to main content

enum Design Pattern

Enum Bit Patterns (12.4.1)

enum to group constants, nested under same namespace

enum for more descriptive alternative to boolean flags

enum for string constants

!snippet set of constants, defined by separate Symbol

const off = Symbol("off")
const info = Symbol("info")

!snippet enum to group set of constants

enum LogLevel {
off = "off",
info = "info",
}

worse than Union of symbol singleton types

type LogLevel =
| typeof off
| typeof info

References