The following code is correct in terms of return type, because then always returns an array of promises.
Promise.resolve(['one', 'two']) .then( arr => { if( arr.indexOf('three') === -1 ) return Promise.reject( new Error('Where is three?') ); return Promise.resolve(arr); }) .catch( err => { console.log(err);
TypeScript throw error:
A type argument for a parameter of type "TResult" cannot be taken out of use. Consider explicitly type arguments. The type argument "void" is not a valid type argument because it is not a supertype of the candidate "string []".
But actually then will never return void .
I can explicitly specify the type .then<Promise<any>> , but this is more like a workaround, rather than a correct solution.
How to write it right?
source share