Type alias Range<Start, Stop, Result, Padding, Current>

Range<Start, Stop, Result, Padding, Current>: Current extends Stop
    ? Current extends Start
        ? [Current]
        : Result extends []
            ? []
            : [...Result, Current]
    : Current extends Start
        ? Range<Start, Stop, [Current], Padding>
        : Result extends []
            ? Range<Start, Stop, [], [...Padding, 0]>
            : Range<Start, Stop, [...Result, Current], Padding>

Creates range between two positive numbers using tail recursion.

Type Parameters

  • Start extends number

    Number to start range

  • Stop extends number

    Number to end range

  • Result extends number[] = []

  • Padding extends 0[] = []

  • Current extends number = [...Padding, ...Result]["length"] & number

Returns

Array with inclusive range from Start to Stop

Example

type Result = Range<1, 3>
// ^? type Result = [1, 2, 3]

Generated using TypeDoc