This package provides two type aliases which allow you to create number ranges easier.
Be aware that this is not a real solution, but a workaround which only works in a very limited range in respect to the bounds of the range. 41 is the current maximum recursion depth, so the max range is 0 | 1 | ... | 40.
import { NumbersToN, NrRange } from "ts-number-range";
// type is equivalent to `0 | 1 | 2 | 3 | 4`
let a: NumbersToN<5>;
// type is equivalent to `4 | 5 | 6 | 7`
let b: NrRange<4, 8>
With TypeScript 4.5-beta a type tail-recursion elimination was introduced. Luckily the provided typings are in the correct form which enables this feature and allows a much greater range.
A quick test resulted in a range from 0 | ... | 997:
So now ranges work for a greater offset too: