JS Built-ins
TypeScriptbeginner

Interface β€” Tuple Type

πŸ“– Usage Example
type Pair = [string, number]
const entry: Pair = ['age', 30]
entry[0]   // β†’ 'age'  (string)
entry[1]   // β†’ 30     (number)

Tuple types enforce fixed-length arrays with specific types at each position.

Tuple Types

A tuple is a fixed-length array where each position has a specific type.

Challenge: Implement createPair<T, U>(first, second) returning a [T, U] tuple.

createPair(1, 'a')   // β†’ [1, 'a']
createPair('x', true) // β†’ ['x', true]
πŸ’‘ Hints (1)
  • β€’ Tuples are just arrays. [first, second] is all you need.