With TypeScript 1.6 and native es6 Promises, I get an error when I use Promise.all([]) with two different return types. For instance:
let onePromise:Promise<string[]> = getOne(); let twoPromise:Promise<MyObject> = getTwo(); Promise.all([onePromise, twoPromise]) .then((values:[string[], MyObject]) => { let one:string[] = values[0]; let two:MyObject = values[1];
In this example, I get an error message in the Promise.all line from the TypeScript error TS2453: 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 'MyObject'. Property 'length' is missing in type 'MyObject'. error TS2453: 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 'MyObject'. Property 'length' is missing in type 'MyObject'.
I actually have another example of this, where the second and third sentences of the error are different from each other, but the first sentence is the same. So basically I'm wondering what the syntax is for “explicitly specifying type arguments”. I don't seem to understand. The code is working fine, but I would like to get rid of this transpiler warning.
source share