Dev Helpers
← Back

Prepend a label to a tuple

Prepend a label to a tuple using TypeScript.

Open this example in the interactive library

Source code

type Point = readonly [x: number, y: number];
const point: Point = [3, 4];
console.log(
  (<T extends readonly unknown[]>(t: T): [string, ...T] => ["point", ...t])(
    point,
  ),
);

Sample output

[ 'point', 3, 4 ]