如何对某些()、过滤()、Each()禁用@typescript-eslint/explicit-function-return-type? [英] How to disable @typescript-eslint/explicit-function-return-type for some(), filter(), forEach()?

查看:24
本文介绍了如何对某些()、过滤()、Each()禁用@typescript-eslint/explicit-function-return-type?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

每次都为some()filter()void声明boolean返回类型非常烦人。

无效

[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上的文档,这将允许您提供对任何函数的内联回调,而无需声明显式返回类型。

这篇关于如何对某些()、过滤()、Each()禁用@typescript-eslint/explicit-function-return-type?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆