0Pricing
TypeScript Academy · Lesson

Enums vs const enum vs union-literal alternatives

Compare classic enums, const enums, and union-literal alternatives; learn trade-offs for DX, size, and safety.

Intro

Goal: See when to use enum, const enum, or union-literal types. You'll compare runtime output, DX, and tree-shaking.

Numeric enum

Numeric enums emit a runtime object and allow reverse mapping. Simple, but they add some bundle size.

enum Direction {
  Left = 0,
  Right = 1
}

const d: Direction = Direction.Left;
console.log(d); // 0

All lessons in this course

  1. Arrays & ReadonlyArray
  2. Tuples & labeled tuples
  3. Enums vs const enum vs union-literal alternatives
← Back to TypeScript Academy