Tuples are fixed-length arrays where each position has its own type. Great for coordinates, pairs, and function results. Use labels for readability and readonly when you don't want mutation.
type Point = [x: number, y: number];type Point = [x: number, y: number];
const origin: Point = [0, 0];
// Readonly tuple
type RGB = readonly [number, number, number];
const red: RGB = [255, 0, 0];
// Function returning a tuple
function useCounter(): [number, () => void] {
let count = 0;
const inc = () => { count += 1; };
return [count, inc];
}
// Variadic tuple (TS 4+)
type WithId<T> = [id: string, ...items: T[]];
const users: WithId<string> = ["team-1", "alice", "bob"];Understanding Tuples is fundamental to mastering TypeScript. Practice with the examples above and experiment with variations to solidify your knowledge.