Tuple

Tuples are available only in TypeScriptThey allow you to have varying types in an array. Tuples come with the implication that the fixed number of elements in an array must be defined while creating the type. For example, if we need an array of string, number, and boolean, it will look like this:

let flexibleArray: [string, number, boolean];flexibleArray = ['John Doe', 24, true] 

When you try to access an index that was not initially created, the new index is added with the appropriate inferred type:

let anotherFlexArray: [string, number];anotherFlexArray = ['John Doe', 24];Assign true to index 2anotherFlexArray[2] = true;// anotherFlexArray becomes ['John Doe', 24, true]

Get TypeScript 2.x for Angular Developers now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.