问题
What is the actual impact of putting void
before promise?
async function doAsyncStuff(){
...
}
function nonAsyncFunction(){
void doAsyncStuff();
}
I couldn't find any official documentation for this, but it must be doing something as it resolves no-floating-promises TSLint error.
回答1:
void is an operator that accepts a value on the Right-Hand Side and evaluates as undefined
.
It resolves no-floating-promises because it does something (or rather, explicitly nothing) with the promise.
来源:https://stackoverflow.com/questions/55558875/void-before-promise-syntax