【问题标题】:lodash's flow() breaks add() in TypeScriptlodash 的 flow() 打破了 TypeScript 中的 add()
【发布时间】:2021-06-09 21:59:21
【问题描述】:
import _ from 'lodash'

const x = _.add(3, 2) // no linting error

const foo = _.flow(
  _.add, // @typescript-eslint/unbound-method
  square,
)

完整的错误描述在https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/unbound-method.md

为什么使用 lodash 的 flow() 会破坏它自己的 add() 并且有解决方案吗?

【问题讨论】:

  • 不幸的是,我无法使用 Typescript 4.3.2 版复制它。您使用哪个版本的 Typescript?另外,您使用哪个版本的 lodash 和 @types/lodash?

标签: typescript lodash eslint


【解决方案1】:

原来这个错误来自recommended-requiring-type-checking eslint 配置。

这种配置比基本的 typescript eslint 更自以为是。因此,我很乐意覆盖这条规则:

.eslintrc.js

...
rules: {
    '@typescript-eslint/unbound-method': 'off', // conflicts with lodash's add()
}

【讨论】:

    猜你喜欢
    • 2019-11-04
    • 2021-10-16
    • 1970-01-01
    • 1970-01-01
    • 2019-06-10
    • 2021-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多