On this page
enum
Prev: `any` | Up: builtins | Next: `namespace`
Rel: as const, builtins, Structural Typing & Narrowing
Ref: TypeScript Docs — enum
Tags: #public #web #typescript #builtins #tier/legacy
Syntax & Overview
enum Direction { Up = 'UP', Down = 'DOWN' }
Generates runtime JavaScript IIFE objects (not erasable syntax; incompatible with Node --experimental-strip-types / erasableSyntaxOnly).
Legacy / Avoid: Prefer as const in all new code.
Notes & Pitfalls
- Emits runtime JavaScript objects: Numeric enums also create reverse mappings and allow assigning arbitrary numbers in older TS.
- Prefer
as constobjects + union types when targeting erasable-types / Node strip-types mode.
Example
enum Status {
Pending = "PENDING",
Done = "DONE",
}
function isComplete(s: Status): boolean {
return s === Status.Done;
}
Linked from
Related notes
- tuts/typescript/builtins/any Linked here; links to this page; shared tags: #builtins, #tier, #typescript, #web
- tuts/typescript/builtins/namespace Linked here; links to this page; shared tags: #builtins, #tier, #typescript, #web
- tuts/typescript/builtins Linked here; links to this page; shared tags: #builtins, #typescript, #web
- tuts/typescript/builtins/as_const Linked here; shared tags: #builtins, #tier, #typescript, #web
- tuts/typescript/type_system/structural_typing_and_narrowing Linked here; shared tags: #typescript, #web
- tuts/typescript/type_system/type_checking_and_erasure_pipeline links to this page; shared tags: #typescript, #web
- tuts/typescript/builtins/asserts shared tags: #builtins, #tier, #typescript, #web
- tuts/typescript/builtins/infer shared tags: #builtins, #tier, #typescript, #web
- tuts/typescript/builtins/is shared tags: #builtins, #tier, #typescript, #web
- tuts/typescript/builtins/keyof shared tags: #builtins, #tier, #typescript, #web