当您忘记在 Javascript 中“等待"一个异步函数时如何发出警告? [英] How to warn when you forget to `await` an async function in Javascript?
问题描述
我正在使用 Babel 和 Webpack.如果我忘记 await
一个异步函数,它通常会被忽视.有时,如果我忘记了 await
,异步函数中会发生错误,并且我会收到 Unhandled promise 拒绝
.然后,我意识到我忘记了await
.
I'm using Babel and Webpack. If I forget to await
an async function, it can often go unnoticed. Once in a while, if I forgot the await
, an error occurs in the async function and I get an Unhandled promise rejection
. Then, I realize that I forgot the await
.
当我忘记添加 await
时,有没有办法得到警告?
Is there a way to get a warning when I forget to add an await
?
推荐答案
我认为 OP 正在从 tslint
中寻找类似 no-floating-promises
的东西,请参阅:
I think OP is looking for something like no-floating-promises
from tslint
see: https://palantir.github.io/tslint/rules/no-floating-promises/
这篇关于当您忘记在 Javascript 中“等待"一个异步函数时如何发出警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!