在承诺语法之前无效 [英] void before promise syntax
本文介绍了在承诺语法之前无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将 void
放在 promise 之前的实际影响是什么?
What is the actual impact of putting void
before promise?
async function doAsyncStuff(){
...
}
function nonAsyncFunction(){
void doAsyncStuff();
}
我找不到任何官方文档,但它必须在解决no-floating-promises
TSLint 错误.
I couldn't find any official documentation for this, but it must be doing something as it resolves no-floating-promises
TSLint error.
推荐答案
void
是一个运算符,它接受右侧的值并计算为 undefined
.
它解决了无浮动承诺,因为它对承诺做了一些事情(或者更确切地说,明确地什么都不做).
It resolves no-floating-promises because it does something (or rather, explicitly nothing) with the promise.
这篇关于在承诺语法之前无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文