Skip to main content

require-await

Disallow async functions which have no await expression.

💭

该规则需要 类型信息 才能运行。


此规则扩展了基本 eslint/require-await 规则。 它使用类型信息添加对返回 Promiseasync 函数的支持。

英:This rule extends the base eslint/require-await rule. It uses type information to add support for async functions that return a Promise.

示例

此规则的 correct 代码示例:

英:Examples of correct code for this rule:

async function returnsPromise1() {
return Promise.resolve(1);
}

const returnsPromise2 = () => returnsPromise1();

如何使用

.eslintrc.cjs
module.exports = {
"rules": {
// Note: you must disable the base rule as it can report incorrect errors
"require-await": "off",
"@typescript-eslint/require-await": "error"
}
};
在线运行试试这个规则 ↗

选项

参见 eslint/require-await 选项

资源

摘自 ❤️ ESLint 内核