Dev Helpers

TypeScript / Conditional types

Infer a tuple element union

Dev Helpers · October 21, 2026

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

Worked example

type ElementOf<T> = T extends readonly (infer U)[] ? U : never;
console.log(((v: ElementOf<[string, number]>) => v)(8));

Result

8

Implementation notes

A union of tuple elements discards their positions. Use indexed access at a specific index when position determines meaning.

Try it yourself

Remove a const assertion and inspect how far the union widens.

Open the TypeScript example →

Editorial date October 21, 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.