At the wicket
Two batters. Always two. Position matters.
A partnership is the pair currently at the wicket. One on strike, one at the non-striker's end. It is exactly two — never one, never three. They rotate strike between overs and ones. When one falls, the next batter walks in. It's still a pair.
TypeScript has a type for that. A tuple is a fixed-size group where each position has a meaning. A partnership is [string, string] — two strings, in that order, no more, no fewer. TypeScript will catch the moment you try to add a third.
Rotate strike. Try to send out a third batter. Watch the umpire's reaction — that's the type system, defending the pair.
The partnership is a tuple.
Two strings, in that order. Position 0 is on strike. Position 1 is the non-striker. Trying to add a third element is a type error.
// A partnership has exactly two players let partnership: [string, string] = ['Sharma', 'Iyer']; // Rotate strike — swap positions partnership = [partnership[1], partnership[0]]; // TypeScript would catch this: // partnership.push('Pierre'); // Error — tuple length is fixed at 2
Arrays are flexible. Tuples are strict.
An array like string[] can hold any number of strings. A tuple like [string, string] holds exactly two strings, in that order. Position matters. Length is locked. TypeScript will catch you the moment you try to break the contract.
The same square brackets, but two very different rules. Use an array when the list can grow. Use a tuple when there is one right shape and nothing else will do.