After examining the type definition of Promise.all
, I noticed that there are 10 different definitions:
/**
* Creates a Promise that is resolved with an array of results when all of the provided Promises
* resolve, or rejected when any Promise is rejected.
* @param values An array of Promises.
* @returns A new Promise.
*/
all<T1, T2, T3>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): Promise<[T1, T2, T3]>;
I only showed the one with an array length of 3, but there are also versions like all<T1>
, all<T1, T2>
, and so on up to all<T1, T2, ..., T9, T10>
.
Interestingly, this conflicts with the actual implementation of Promise.all
, which can accept an input array exceeding the limit of 10:
let myPromise = num => Promise.resolve(num);
let myPromisesArray = (new Array(20))
.fill()
.map((_,i) => myPromise(i));
Promise.all(myPromisesArray).then(console.log)
While I consider myself decent at development, I defer to the expertise of the Microsoft developers who created the ES2015 type definition, leading me to question:
Why does the type definition for Promise.all not align with either its documentation or its actual functionality?