I am currently researching this issue myself, and here are some of my results.
type ResultField<Index extends number, Result extends number[] = []> = Result['length'] extends Index ? Result[number] : ResultField<Index, [...Result, Result['length']]>;
type Range<Min extends number, Max extends number> = Exclude<ResultField<Max>, ResultField<Min>> | Max;
interface Input {
zeroTo5: ResultField<6>
threeTo5: Range<3, 5>
}
const in:Input = {
zeroTo5: 0 | 1 | 2 | 3 | 4 | 5,
threeTo5: 3 | 4 | 5
}
As you can see, the code hints for Range<3, 5>
in webStorm are not as comprehensive as those for ResultField<6>
, but I still think these are the answers you need.