- 01Getting Started
- 02Your First Output (console.log)
- 03Variables and Type Annotations (number/string/boolean)
- 04Array Types
- 05Function Types (Parameters and Return Values)
- 06Optional Parameters and Default Parameters
- 07Interfaces (interface)
- 08Optional Properties (?)
- 09Type Aliases (type)
- 10Union Types
- 11Literal Types
- 12enum (Enumerated Types)
- 13Classes and Types
- 14Inheritance (extends) and Implementing an Interface (implements)
- 15Generics (<T>)
- 16Tuple Types
- 17The any and unknown Types
- 18Type Assertions (as)
- 19The readonly Modifier
- 20[Applied] Build a Mini Inventory Management System
Tuple Types
This lesson covers tuple types โ an array with a fixed number of elements and a fixed type for each one. It's for anyone searching "TypeScript tuple usage."
A tuple type is written as [Type1, Type2, ...], letting you specify a different type at each position of the array. Unlike a regular array, both the number of elements and their order are fixed as part of the type.
The example defines a tuple type, type NameAge = [string, number];, treating a name and an age as one bundled pair, then unpacks each element into its own variable using destructuring.
A common early mistake is not seeing the difference from a regular array (like string[]). A regular array can hold any number of elements, while a tuple type is different in that each position has a fixed meaning โ "first is a string, second is a number."
In real projects, tuple types are used when a function returns multiple values bundled together, or to represent a "fixed-order pair" like a coordinate (x, y).
๐งช This site can't compile or run TypeScript directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ nothing is sent anywhere).
