Tuples In Type Script
Tuples in Action
A tuple is a data structure that represents an item by placing its properties into distinct indices.
So instead of an object,
you can represent it as a tuple.
However, JavaScript doesn't natively support tuples. In reality, the code snippet above is just an array. That means you can mess with the order.
TypeScript gives us the ability to convert our array into a real tuple!
Why Tuples?
Generally, tuples aren't great for representing a piece of data because the indices aren't meaningful. Most of the time, a piece of data is better represented as an object because it associates values to named keys.
But in any case, it's good to know its existence in TypeScript!
Last updated