79281270

Date: 2024-12-14 19:45:49
Score: 1
Natty:
Report link

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
}

enter image description here enter image description here

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.

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: accbear