Closed
Description
This (apparently valid) code compiled OK with TypeScript 2.0:
function f(): Promise<void> {
return Promise.resolve(4).then((n: number) => {
if (n !== 200) {
return Promise.reject('error');
}
return Promise.resolve();
});
}
With TypeScript 2.1.4 it gives:
test.ts(2,10): error TS2322: Type 'Promise' is not assignable to type 'Promise'.
Type 'number' is not assignable to type 'void'.
tsconfig.json
:
{
"compilerOptions": {
"target": "es5",
"lib": ["es2015"]
}
}
It seems that the problem comes when promises are chained. For instance when removing the .then()
chain, compilation runs without any error:
function f(n: number): Promise<void> {
if (n !== 200) {
return Promise.reject('error');
}
return Promise.resolve();
}