A non-negative integer literal type to increment.
type Five = Increment<4>; // 5
type One = Increment<0>; // 1
type Ten = Increment<9>; // 10
// Useful in recursive type computations
type CountToN<N extends number, Count extends number = 0> =
Count extends N ? Count : CountToN<N, Increment<Count>>;
type UpTo5 = CountToN<5>; // 5
// Building sequences
type Range<From extends number, To extends number> =
From extends To
? From
: From | Range<Increment<From>, To>;
type OneToFive = Range<1, 5>; // 1 | 2 | 3 | 4 | 5
Increments a non-negative integer literal type
Nby 1.This utility performs compile-time arithmetic by leveraging TypeScript's tuple length calculation. It creates a tuple of length
N, prepends an element, and returns the new length type. This effectively computesN + 1at the type level.Note: Due to TypeScript's recursion limits, this works reliably for small to medium integers (typically up to a few hundred, depending on the TypeScript version and configuration).