Dev Helpers

TypeScript / Coordinate systems

Reflect a coordinate across the vertical axis

Dev Helpers · November 20, 2026

Reflection across the vertical axis changes the horizontal sign and leaves the vertical coordinate in place. Return a new point when callers retain the original.

Worked example

type Point = readonly [x: number, y: number];
const a: Point = [3, 4],
  b: Point = [7, 1];
console.log((([x, y]: Point): Point => [-x, y])(a));

Result

[ -3, 4 ]

Implementation notes

Floating-point coordinates can accumulate small rounding errors after repeated transformations. Test numerical behaviour separately from type correctness.

Try it yourself

Reflect a point on the axis and then reflect an off-axis point twice.

Open the TypeScript example →

Editorial date November 20, 2026 · Published December 6, 2026

Related articles

Reject fractional cent amounts

A numeric type cannot by itself guarantee whole cents. Validate integrality where money enters the typed part of the application.

Infer route names from a registry

A route registry can drive both lookup and allowed route names. Type the keys from the registry so a removed route cannot survive in a separate union.

Infer a tuple element union

Indexing a tuple's type by number yields a union of its element types. Literal inference determines how precise that union becomes.