Answers for "typescript type number range"

0

typescript range

const range = (start, end) => Array.from({length: (end - start)}, (v, k) => k + start);
Posted by: Guest on August-24-2021
0

typescript type number range

type PrependNextNum<A extends Array<unknown>> = A['length'] extends infer T ? ((t: T, ...a: A) => void) extends ((...x: infer X) => void) ? X : never : never;

type EnumerateInternal<A extends Array<unknown>, N extends number> = { 0: A, 1: EnumerateInternal<PrependNextNum<A>, N> }[N extends A['length'] ? 0 : 1];

export type Enumerate<N extends number> = EnumerateInternal<[], N> extends (infer E)[] ? E : never;

export type Range<FROM extends number, TO extends number> = Exclude<Enumerate<TO>, Enumerate<FROM>>;
Posted by: Guest on December-16-2020

Code answers related to "TypeScript"

Browse Popular Code Answers by Language