Sometimes I may need to limit the value range of a variable, and I expect to get the following types.
type Range<start, end, step extends number = 1> = ?
type a1 = Range<1000, 2000>; // 1000 | 1001 | 1002 | ... | 2000
type a2 = Range<1000, 2000, 2>; // 1000 | 1002 | ... | 2000
The above code allows me to have a Range of values between 1000 and 2000, although the values I want may be larger, such as 5000 and above. So Far I've only written a Range of 1000, i have no idea how to implement a Range that supports large numbers.
——————————————————————————————————————————
I accepted the help of netizens, and now I have written the Range function I want, you can check this link:link
The range supports up to tens of thousands of numbers, but too large a range of numbers may have performance problems, I think if the range of more than ten thousand to do further optimization can have better performance, but I have not yet supported.