Skip to content
dreamcode
dreamcode
Map
Enums
Lesson 11 of 26
+15 XP on finish
TYPESCRIPTChapter 2 · TS Unions & Enums

Literal Types and Enums

Literal Types restrict values to specific strings or numbers. Enums group related constants, providing a named list of numeric or string options.

Worked example

How it reads

  • 'dusk' | 'neon' forces the theme to match only those literals
  • enum Direction creates lookup constants available at runtime
Cloud tip: Default to union literal types for simplicity unless you need lookup constants.
index.ts
TYPESCRIPT
type-checked, then run in your browser
Console
Run your code to see its output here.
YOUR TURN

Add Orbit = 2 to FlightState, then log FlightState.Orbit and FlightState[2]: 2 then Orbit.

Press Run to check your work.