First of all, thanks a lot for this refactoring, I think it's really useful and will push the adoption of async-await syntax 👍
This is a bug report related to this Twitter conversation: The converted code does not await for Promise.reject, thus the runtime does not throw but returns Promise.reject(3), which does not trigger the catch-clause but makes the function call return a rejected Promise.
I'm not 100% sure what the best conversion would be, but I assume it would be to always await for functions that could possibly return a Promise or expressions that are a Promise.
TypeScript Version: Tested against https://github.com/Microsoft/TypeScript/tree/v3.1.1 and 4ed85b7
Failing testcases:
These assume that the correct behavior is to add await to a returned expression that yields a Promise.
Search Terms:
Code
function testcase() {
return Promise.resolve(1)
.then(x => Promise.reject(2))
.catch(err => console.log(err));
}
Running testcase() code will log 2 and the returned Promise will resolve to undefined.
Expected behavior:
async function testcase() {
try {
const x = await Promise.resolve(1);
return await Promise.reject(2);
}
catch (err) {
return console.log(err);
}
}
A call to testcase() would print 2 and the returned Promise would resolve to undefined as above.
Actual behavior:
async function testcase() {
try {
const x = await Promise.resolve(1);
return Promise.reject(2);
}
catch (err) {
return console.log(err);
}
}
A call to testcase() this won't print 2 but node will complain about an unhandled rejected promise.
Related Issues:
First of all, thanks a lot for this refactoring, I think it's really useful and will push the adoption of async-await syntax 👍
This is a bug report related to this Twitter conversation: The converted code does not
awaitforPromise.reject, thus the runtime does not throw but returnsPromise.reject(3), which does not trigger thecatch-clause but makes the function call return a rejected Promise.I'm not 100% sure what the best conversion would be, but I assume it would be to always await for functions that could possibly return a
Promiseor expressions that are aPromise.TypeScript Version: Tested against https://github.com/Microsoft/TypeScript/tree/v3.1.1 and 4ed85b7
Failing testcases:
master: https://github.com/rradczewski/TypeScript/tree/bug-return-needs-await (master...rradczewski:bug-return-needs-await)v3.1.1: https://github.com/rradczewski/TypeScript/tree/bug-v3.1.1-return-needs-await (v3.1.1...rradczewski:bug-v3.1.1-return-needs-await)These assume that the correct behavior is to add
awaitto a returned expression that yields a Promise.Search Terms:
Code
Running
testcase()code will log2and the returned Promise will resolve toundefined.Expected behavior:
A call to
testcase()would print2and the returned Promise would resolve toundefinedas above.Actual behavior:
A call to
testcase()this won't print2but node will complain about an unhandled rejected promise.Related Issues:
await console.log(...)awaittoconsole.log