Looking at the type definition of Promise.all
, I see 10 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 included the one with an array of length 3, but there also exist all<T1>
, all<T1, T2>
, all the way up to all<T1, T2, ..., T9, T10>
.
However, this doesn't match with the implementation of Promise.all
, which can take as an input an array longer than 10:
let myPromise = num => Promise.resolve(num);
let myPromisesArray = (new Array(20))
.fill()
.map((_,i) => myPromise(i));
Promise.all(myPromisesArray).then(console.log)
I'm not the worst developer in the world but still, I make the assumption that the Microsoft developers who produced the type definition of ES2015 know more about JS/TS than me, which begs the question:
Why the type definition of Promise.all doesn't match with neither its documentation nor its implementation?