Dev Helpers

TypeScript / Tuple types

Calculate a point magnitude

Dev Helpers · December 11, 2025

A coordinate type makes a numeric operation's inputs explicit. Magnitude combines dimensions into a single scalar, so the result loses direction.

Worked example

type Point = readonly [x: number, y: number];
const point: Point = [3, 4];
console.log(Math.hypot(...point));

Result

5

Implementation notes

Declare coordinate units alongside the type when more than one coordinate system enters the same feature. Two numbers alone cannot distinguish pixels from metres.

Try it yourself

Compare points with equal lengths and opposite signs.

Open the TypeScript example →

Editorial date December 11, 2025 · 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.