Dev Helpers
← Back

Preserve coordinates in a readonly tuple list

Preserve coordinates in a readonly tuple list 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(
  ([point, [0, 0]] satisfies readonly Point[]).map(([x, y]) => x + y),
);

Sample output

[ 7, 0 ]