TypeScript · Junior · Question 14 of 75
What is a tuple in TypeScript?
- ✓Correct answer: A fixed-length array with a known type for each element
- 2An array of any length where all elements have the same type
- 3An immutable object with numeric keys instead of property names
Explanation
type Point = [number, number] - exactly two numbers. Tuples are handy for returning several values, as in useState: [value, setter]. Elements can be named ([x: number, y: number]) and made optional ([string, number?]).