-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v3.7.2 Promise.all (No overload matchs this call) with different promise types and more than 10 promises #35617
Comments
You can probably use declaration merging to implement your own promise.all with 11,12,13+-tuples |
A month later: "No overload with more than 150 promises" |
@MartinJohns I honestly had that problem for quite a bit, before tuple types+rest args were introduced. I ended up writing code generators that would generate Sometimes, it would cause compile times to slow and I would have to reduce the value of It was always a struggle between supporting edge cases with high Even now, I still have problems with it, sometimes, but for trampoline types. Where I support |
@AnyhowStep six months later: "No overload with more than 2147483647 promises" In all seriousness, it's always a compromise, and declaration merging and custom overloads seem like the best option for such specific corner cases. |
Anyone literally passing in two billion promises to But yeah, it’s frustrating when you can’t easily write a single type to handle “arbitrary number of Xs” and have to resort to overloads or the like. That’s why I love changes like the recursive type aliases PR that enabled JSON-like types. |
Actually you can: #27179 For type UnwrapPromise<T> = T extends Promise<infer R> ? R : T;
declare function PromiseAll<T extends Array<any> | [any]>(
promises: T,
): Promise<{ [K in keyof T]: UnwrapPromise<T[K]> }>;
// a infered as Promise<[number, string]>
const a = PromiseAll([
Promise.resolve(3),
Promise.resolve('foo'),
]);
// b infered as Promise<[0,1,2,3,4,5,6,7,8,9,10,11,12,13]>
const b = PromiseAll([
Promise.resolve(0 as const),
Promise.resolve(1 as const),
Promise.resolve(2 as const),
Promise.resolve(3 as const),
Promise.resolve(4 as const),
Promise.resolve(5 as const),
Promise.resolve(6 as const),
Promise.resolve(7 as const),
Promise.resolve(8 as const),
Promise.resolve(9 as const),
Promise.resolve(10 as const),
Promise.resolve(11 as const),
Promise.resolve(12 as const),
Promise.resolve(13 as const),
]);
const l: Array<string | number> = [];
// c infered as Promise<Array<string | number>>
const c = PromiseAll(l); |
I meet this issue with V4.0.3, |
TypeScript Version: v3.7.2
Search Terms:
Promise.all
,No overload matchs this call
Expected behavior:
Use a variable number of promises in a Promise.all call
Actual behavior:
If we use more than 10 promises, and these promises return different types, the compiler throws a error
Related Issues:
Code
Output
Compiler Options
Playground Link: Provided
The text was updated successfully, but these errors were encountered: