...

/

Creating a strongly-typed tuple

Creating a strongly-typed tuple

In this lesson, we will learn what tuples are and how we can use them in TypeScript.

Understanding a tuple #

A tuple can be thought of as an array with a fixed number of elements. Some of React’s hooks return tuples. Can you guess those hooks?

Tuples are useful when we want to store multiple bits of data. Tuples are a little more concise than an object but aren’t as self-documenting as objects. Tuples are nice for small and obvious data structures.

The tuple type doesn’t exist in JavaScript. The closest we have are arrays, but there is no way of enforcing ...