A positive integer literal type (must be >= 1) to decrement.
type Three = Decrement<4>; // 3
type Zero = Decrement<1>; // 0
type Four = Decrement<5>; // 4
// type Error = Decrement<0>; // ⚠️ Error: will fail or return unexpected result
// Useful in countdown scenarios
type Countdown<N extends number> =
N extends 0 ? 0 : N | Countdown<Decrement<N>>;
type CountdownFrom3 = Countdown<3>; // 3 | 2 | 1 | 0
// Bounds checking
type IsPositive<N extends number> =
N extends 0 ? false : N extends Decrement<Increment<N>> ? true : false;
Decrements a positive integer literal type
Nby 1.This utility performs compile-time arithmetic by leveraging TypeScript's tuple manipulation. It creates a tuple of length
N, removes the first element usingList.Tail, and returns the new length type. This effectively computesN - 1at the type level.Warning: This requires
Nto be positive (>= 1). Attempting to decrement 0 will likely result in compilation errors or unexpected behavior.