In VS Code, I noticed that sometimes, it seems to indicate available code actions to convert a Promise.then()
function to async/await
with the three grey dots but then, when actually trying to execute the Quick Fix, it shows "No code actions available".
From my investigation, this seems to happen because one of the Promises inside the function has an any
type.
I've found the current behavior really confusing because the combination of the three grey dots and then an unavailable Quick Fix is a strange combination.
TypeScript Version: 3.6.0-dev.20190808
Search Terms: code action async await promise
Code
let somePromise;
function myFunction() { // VS Code shows three grey dots and "This may be converted to an async function.ts(80006)" on hover
return Promise.resolve()
.then(() => {
return somePromise
.then(() => {
return 'Yeah!';
});
});
}
Expected behavior:
Either:
- VS Code doesn't indicate an available code action in the first place
- It provides some kind of hint why it can't execute a quick fix or how to enable it
- The code action still works and does the conversion anyway
Actual behavior:
VS Code shows a possible available code action but then there is none
4条答案
按热度按时间js5cn81o1#
引用 @sandersn from #32744 :
次要期望:为每个建议提供一个代码修复。但这里没有代码修复。(诚然,有时会出现没有代码修复的建议...
听起来我们并不完全 保证 每个建议都有一个代码修复,但在可能的情况下这是可取的。我的猜测是建议主要由语法决定,但代码修复依赖类型信息来产生更改。当遇到
any
时,代码修复可能会更加宽容。j8ag8udp2#
VS Code一开始没有显示可用的代码操作
VS Code显示了一个可能的可用代码操作,但实际上并没有
顺便说一下,灯泡图标表示代码操作的可用性;三个小点表示建议诊断。但后者几乎总是与前者相伴而行,因此这种困惑是可以理解的,很可能其他用户也有同样的经历。
jdzmm42g3#
但是后者几乎总是与前者相伴而行,因此这种困惑是可以理解的,可能也是其他用户所共享的。
不仅如此,而且这些点总是可见的,而只有在点击线条或将其悬停一段时间后,灯泡才会显示出来。所以如果你在浏览代码时寻找快速修复的机会,你所要做的就是查看灰色的点...系统地检查它们以寻找快速修复并发现许多都没有可用的,这有点烦人。如果能提前知道这一点,就不必如此频繁地进行手动点击操作了。
ghhkc1vu4#
Same problem here.
This may be converted to an async function. ts(80006)
No quick fixes available