diff --git a/types/Promise.d.ts b/types/Promise.d.ts index 7789335..372a085 100644 --- a/types/Promise.d.ts +++ b/types/Promise.d.ts @@ -387,7 +387,7 @@ interface PromiseConstructor { * return Promise.all(promises) * ``` */ - all: >(values: readonly [...T]) => Promise<{ [P in keyof T]: Awaited }>; + all: >>(promises: T) => Promise<{ [P in keyof T]: Awaited }>; /** * Accepts an array of Promises and returns a new Promise that resolves with an array of in-place Statuses when all input Promises have settled. This is equivalent to mapping `promise:finally` over the array of Promises. @@ -402,7 +402,7 @@ interface PromiseConstructor { * return Promise.allSettled(promises) * ``` */ - allSettled: (promises: Array>) => Promise>; + allSettled: >>(promises: T) => Promise<{ [P in keyof T]: Promise.Status }>; /** * Accepts an array of Promises and returns a new promise that is resolved or rejected as soon as any Promise in the array resolves or rejects. @@ -422,7 +422,7 @@ interface PromiseConstructor { * return Promise.race(promises) * ``` */ - race: (promises: Array>) => Promise; + race: >(promises: ReadonlyArray) => Promise>; /** * Accepts an array of Promises and returns a Promise that is resolved as soon as `count` Promises are resolved from the input array. The resolved array values are in the order that the Promises resolved in. When this Promise resolves, all other pending Promises are cancelled if they have no other consumers. @@ -439,7 +439,10 @@ interface PromiseConstructor { * return Promise.some(promises, 2) -- Only resolves with first 2 promises to resolve * ``` */ - some: (promises: Array>, count: number) => Promise>; + some: , N extends number>( + promises: ReadonlyArray, + count: N, + ) => Promise, N>>; /** * Accepts an array of Promises and returns a Promise that is resolved as soon as _any_ of the input Promises resolves. It will reject only if _all_ input Promises reject. As soon as one Promises resolves, all other pending Promises are cancelled if they have no other consumers. @@ -455,7 +458,7 @@ interface PromiseConstructor { * return Promise.any(promises) -- Resolves with first value to resolve (only rejects if all 3 rejected) * ``` */ - any: (promises: Array>) => Promise; + any: >(promises: ReadonlyArray) => Promise>; /** * Returns a Promise that resolves after `seconds` seconds have passed. The Promise resolves with the actual amount of time that was waited. @@ -621,3 +624,24 @@ declare namespace Promise { } declare const Promise: PromiseConstructor; + +/** internal */ +declare namespace TS { + /** Returns a Tuple of size N filled with T */ + type BuildTupleUnchecked = []> = A extends { length: infer L } + ? L extends N + ? A + : BuildTupleUnchecked + : never; + + /** Returns a Tuple of size N filled with T, but defaults to Array if N is `number`, or negative, or a decimal. */ + type BuildTuple = N extends number + ? number extends N + ? Array + : `${N}` extends `-${string}` + ? Array + : `${N}` extends `${string}.${string}` + ? Array + : BuildTupleUnchecked + : never; +}