Tuple Types


Tuples in TypeScript allow you to express an array where the type of a fixed number of elements is known but does not have to be the same. You can define a tuple as:

let x: [string, number];
x = ["hello", 10]; // OK
x = [10, "hello"]; // Error

Exercise

Create a function that accepts a tuple with a string and a number, and returns a message containing both.


Copyright © learn-ts.org. Read our Terms of Use and Privacy Policy