Closed
Description
TypeScript Version: 3.7.2 (refactoring in VSCode 1.40.1 using 3.6.3)
Search Terms: Convert to async function catch
Code
// Original function
function combine1(a: Promise<any>, b: Promise<any>) {
return a.catch(() => b)
}
// Result of "Convert to async function" in VSCode
async function combine2(a: Promise<any>, b: Promise<any>) {
try {
return a;
}
catch (e) {
return await b;
}
}
async function test() {
const a1 = Promise.reject('nay1')
const b1 = Promise.resolve('yay1')
console.log("combine1:", await combine1(a1, b1))
const a2 = Promise.reject('nay2')
const b2 = Promise.resolve('yay2')
console.log("combine2:", await combine2(a2, b2))
}
test()
Expected behavior:
Converted code should be functionally equivalent to original code. I believe return await a
would be correct.
Actual behavior:
Converted code is not equivalent as the example shows.
Playground Link:
Related Issues:
Related to async refactoring: #27641, #27621
VSCode info:
Version: 1.40.1
Commit: 8795a9889db74563ddd43eb0a897a2384129a619
Date: 2019-11-13T16:47:44.719Z
Electron: 6.1.2
Chrome: 76.0.3809.146
Node.js: 12.4.0
V8: 7.6.303.31-electron.0
OS: Darwin x64 18.7.0
Sorry if this should be reported on VSCode, I saw similar bugs have been transferred from there to here.