typescript - 如何为 some()、filter()、forEach() 禁用@typescript-eslint/explicit-function-return-type?

标签 typescript eslint

如何禁用 @typescript-eslint/explicit-function-return-type对于 some(), filter(), forEach()?

some()filter()void 声明一个 boolean 返回类型是很烦人的每次都为 forEach()

无效

[2, 5, 8, 1, 4].some(elem => elem > 10)

有效

[2, 5, 8, 1, 4].some((elem):boolean => elem > 10)

我希望能够使用第一个模式(标记为“无效”)而不会因该规则而出错。

最佳答案

在您的 .eslintrc 文件中,您可以在 rules 下添加以下内容:

{
  ...
  "plugins": ["@typescript-eslint"],
  "rules": {
    ...
    "@typescript-eslint/explicit-function-return-type": {
      "allowExpressions": true
    }
  }
}

根据 allowExpressions 上的文档,这将允许您在不声明显式返回类型的情况下为任何函数提供内联回调。

关于typescript - 如何为 some()、filter()、forEach() 禁用@typescript-eslint/explicit-function-return-type?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56907336/

相关文章:

reactjs - 根据 api url 中的数据格式化react.js 中的日期

javascript - 如何使用 eslint 验证 VSCode 中的 Adob​​e Extendscript (.jsx) 文件

node.js - 如何使用 Promise.all 迭代对象键

javascript - 单击图标打开文件资源管理器

node.js - 覆盖 eslint-plugin-mocha 规则上的错误消息

javascript - ESLint prefer-arrow-callback 错误

javascript - 忽略 moment.js 的 eslint 错误

reactjs - Eslint 与 React CSS 模块

error-handling - 如何两次处理异常

javascript - 如何将 0 传递给 TypeScript 可选参数?