Arrays and Tuples

Learn how to take full control of lists in TypeScript using typed arrays and tuples that are structured, safe, and deeply expressive.

JavaScript arrays are flexible—sometimes too flexible. We can mix types. Push in anything. Return all kinds of shapes. And JavaScript won’t say a word until something breaks at runtime.

This is where TypeScript steps in—not to slow us down, but to lock things in. It gives us tools to say, “This array holds only strings” or “This collection will always have exactly two items: first a name, then a score.” We make our expectations clear, and the compiler enforces them with zero compromise.

Typed arrays and tuples don’t just catch bugs—they communicate intent. They make our code more readable and more testable.

Let’s dig in.

Typed arrays: Predictability with every element

Here’s a basic example. Imagine we’re tracking blog tags, user IDs, and boolean flags. This is what it might look like in plain JavaScript: