-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
es6-promise Promise.all error #5935
Comments
If you're using https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/es6-promise/es6-promise.d.ts#L59, I found it's because those two items in the array resolve to different promise types. Try specifying it explicitly, usually works for me:
Edit: Wrong syntax, but |
Can you help me understand why this can't be inferred? On Fri, 4 Dec 2015, 18:01 Blake Embrey notifications@github.com wrote:
|
I'm not the best person for that, I'll leave it for the TypeScript team to answer. |
@blakeembrey I believe this is the correct syntax:
If you try adding |
Not causing issues for me. (link) What version (of TypeScript) are you using? |
Yes, that works. Sorry, I was trying to say the type assertion you provided didn't work ( This is what I have ended up with: Promise.all<string | number>([
Promise.resolve('1'),
Promise.resolve(1)
])
.then(([x, y]: [string, number]) => {
x
y
}) I provide the type of the tuple in the Promise.all<string | number>([
Promise.resolve('1'),
Promise.resolve(1)
])
.then(([x, y]) => {
x
y
}) … then the compiler wouldn't know if This is a bit of a PITA. I'm trying to understand if it's possible to write a better type definition for |
Right, I understand. I don't think it's currently possible to do that since there's no way to express the generic variadically, but this discussion might relate to the proposal in #5453. The TypeScript team should chime in if there's a better approach at the moment, but I've done the same thing as you ended up with in the past. |
untill #5453 is in, we can add a punch of overloads (say 2-10) to make interface PromiseConstructor {
all<T1, T2>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>]): Promise<[T1, T2]>;
all<T1, T2, T3>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>]): Promise<[T1, T2, T3]>;
all<T1, T2, T3, T4>(values: [T1 | PromiseLike<T1>, T2 | PromiseLike<T2>, T3 | PromiseLike<T3>, T4 | PromiseLike<T4>]): Promise<[T1, T2, T3, T4]>;
..............
} @sandersn thoughts? |
Yes, multiple overloads is the accepted workaround until we have variadic generics from #5453. I put variadic kinds behind this-types functions because this-types don't have a simple (albeit verbose) workaround. So I think it's worthwhile to add the overloads now until variadic kinds are in. I'll link the PR when it's done. |
Here's the PR: #5973. |
When I use the es6-promise type definitions, given this code:
I get the following error:
Can you explain why this is? I don't understand the error.
The text was updated successfully, but these errors were encountered: