Tuple Type
Question
What is a tuple type in TypeScript?
Hint
Tuples are like arrays but with fixed structure.
Explanation
A tuple is a fixed-length array where each element has a specific known type. type Pair = [string, number]. const p: Pair = ["hello", 42]. Unlike regular arrays (string[]), tuples have a fixed number of elements with specific types at each position. Tuples support optional elements ([string, number?]), rest elements ([string, ...number[]]), and labeled elements ([name: string, age: number]). Tuples are useful for key-value pairs, coordinate pairs, and function return values with multiple values.
Related Resources
Related Lessons
- Arrays & Tuples
Learn arrays/tuples.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.