Tuples
A tuple is an exact sequence of values.
When TypeScript infers that an array might contain multiple data types, it creates a type union of the various types. Defining a type as a tuple allows TypeScript to infer the type when you access specific elements of the tuple.
Define as tuple
const row: [string, number] = [ "Sam", 42 ]
Loading TypeScript...
Notice that you will get a tuple error if the specified sequence is not matched exactly.
Loading TypeScript...