Skip to content

Commit

Permalink
feat(Util): Add NumericRange<Start, End>
Browse files Browse the repository at this point in the history
  • Loading branch information
SirWrexes committed Aug 16, 2023
1 parent ef26afb commit 7d2cd97
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions types/Util.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,17 @@ export namespace PickByType {
[k in keyof T as T[k] extends ToPick | object ? k : never]: T[k] extends object ? Deep<T[k], ToPick> : T[k]
}
}

type CreateArrayWithLength<Length extends number, Accumulator extends never[] = []> = Accumulator['length'] extends Length
? Accumulator
: CreateArrayWithLength<Length, [...Accumulator, never]>

type NumericRangeCreator<StartArray extends never[], End extends number, Accumulator extends number = never> =
StartArray['length'] extends End
? Accumulator | End
: NumericRangeCreator<[...StartArray, never], End, Accumulator | StartArray['length']>

/**
* Create a union type of number ranging from {@link Start} to {@link End}
*/
export type NumericRange<Start extends number, End extends number> = NumericRangeCreator<CreateArrayWithLength<Start>, End>

0 comments on commit 7d2cd97

Please sign in to comment.