Docs
/
TypeScript
Chapter 3

03 — Arrays, Tuples & Enums

Core Concepts

  • Typed Arraysstring[] or Array<string> syntax
  • Readonly Arraysreadonly string[] or ReadonlyArray<string>
  • Tuples — fixed-length arrays with specific types per position
  • Labeled Tuples — tuples with named elements for readability
  • Numeric Enums — auto-incrementing numeric values
  • String Enums — explicit string values (preferred)
  • const Enums — inlined at compile time, no runtime object
  • Enum alternativesas const objects (often preferred over enums)

Array vs Tuple

FeatureArrayTuple
LengthVariableFixed
Element typesAll sameCan differ per position
Push/popYesAllowed but defeats purpose
DestructuringTyped uniformlyEach position typed

Enum Best Practices

  • Prefer string enums over numeric (readable, debuggable)
  • Consider as const objects instead of enums (tree-shakeable, no runtime overhead)
  • Use const enum only if bundle size matters and you accept the trade-offs