here is a pattern that gets the next number in types domain
type Nums = [1, 2, 3, 4, 5, 6, 7, 8, 9];
type Num = Nums[number];
type Next<N extends Num> = Nums[N] extends number ? Nums[N] : never;
type N2 = Next<1>; // 2
is there a way to get a previous number?
Not sure why you'd want this, but isn't it obvious?
type Nums = [-1, 0, 1, 2, 3, 4, 5, 6, 7];
type Num = Nums[number];
type Prev<N extends Num> = Nums[N] extends number ? Nums[N] : never;
type N2 = Prev<1>; // 0
can you use the original sequence?
Shouldn't this be on Stack Overflow?
type Prev<N extends Num> = { [K in Num]: N extends Next<K> ? K : never }[Num];
// Prev<1> is never, just like Next<9> is never. 🤷♂️
Most helpful comment
Shouldn't this be on Stack Overflow?