Readonly

What

By default, tuples are still arrays under the hood, meaning you can technically use methods like push() or pop() to change their length. Readonly tuples prevent these mutations.

How

You mark a tuple as immutable by adding the readonly keyword before the bracket notation:

const ticket: readonly [string, number] = ["SUPPORT-123", 42];

// Error: Property 'push' does not exist on type 'readonly [string, number]'.
ticket.push("extra");

Why

Since the primary benefit of a tuple is its fixed structure, allowing mutations like push undermines its type safety. Using readonly ensures the tuple’s length and content remain exactly as defined during initialization.

Summary

Use readonly tuples whenever possible to enforce true immutability at compile-time.