You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The type argument for type parameter 'R' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
Type argument candidate 'string' is not a valid type argument because it is not a supertype of candidate 'string[]'.
Can you explain why this is? I don't understand the error.
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.
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.
Activity
blakeembrey commentedon Dec 4, 2015
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
Promise.all<Promise<string> | Promise<string[]>>works.OliverJAsh commentedon Dec 4, 2015
Can you help me understand why this can't be inferred?
On Fri, 4 Dec 2015, 18:01 Blake Embrey notifications@github.com wrote:
blakeembrey commentedon Dec 4, 2015
I'm not the best person for that, I'll leave it for the TypeScript team to answer.
OliverJAsh commentedon Dec 4, 2015
Blake Embrey (@blakeembrey) I believe this is the correct syntax:
If you try adding
.then((x) => x)to the end of your assertion, you get errors.blakeembrey commentedon Dec 4, 2015
Not causing issues for me. (link) What version (of TypeScript) are you using?
OliverJAsh commentedon Dec 4, 2015
Yes, that works. Sorry, I was trying to say the type assertion you provided didn't work (
Promise.all<Promise<string> | Promise<string[]>>).This is what I have ended up with:
I provide the type of the tuple in the
thencallback function so I can continue to use the type checker. If I did the following:… then the compiler wouldn't know if
xis a string or number.This is a bit of a PITA. I'm trying to understand if it's possible to write a better type definition for
Promise.allso assertions are not needed?blakeembrey commentedon Dec 4, 2015
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.
mhegazy commentedon Dec 7, 2015
untill #5453 is in, we can add a punch of overloads (say 2-10) to make
Promise.allmore user friendly. something like:Nathan Shively-Sanders (@sandersn) thoughts?
sandersn commentedon Dec 7, 2015
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.
sandersn commentedon Dec 7, 2015
Here's the PR: #5973.