【问题标题】:ESLint reports no-undef error on flow-typed global typesESLint 在流类型的全局类型上报告 no-undef 错误
【发布时间】:2017-12-18 17:44:02
【问题描述】:

我在/flow-typed/redux.flow.js 中定义了全局类型:

declare type Action = {|
  +type: string,
  +payload: any,
|}

declare type State = {|
  +ui: UI,
  +user: User,
  +team: Team,
  +projects: Project[],
  +profile: Profile,
|}

declare type UI = {|
  +isSliderOpen: boolean,
  +isModalVisible: boolean,
  +modalAction: string,
  +modalPayload: Object,
|}

...

我已将 airbnb eslint 配置添加到我的项目中,现在我得到:

type Props = {
  logout: () => Action, //error ESLint 'Action' is not defined.(no-undef)
  user: UserDetails, //error ESLint 'UserDetails' is not defined.(no-undef)
}

这纯粹是 eslint 的错误。一切都已正确配置,并且流程本身很愉快。

如何告诉 eslint 这些类型确实被声明为全局的?还是我应该将它们添加到一些忽略列表中?

【问题讨论】:

    标签: reactjs eslint flowtype eslint-config-airbnb


    【解决方案1】:

    事实证明(就像我想的那样)方法不是将全局类型添加到 eslint 忽略列表。实际上它都是由我已经安装的eslint-plugin-flowtype 处理的,但我没有像这样扩展它:

    .eslintrc

    "extends": ["airbnb", "plugin:flowtype/recommended"],
    "plugins": [
      "flowtype"
    ],
    

    【讨论】:

      【解决方案2】:

      您可以在文件内、eslint 配置文件或 package.json 中使用 cmets 定义全局变量。在eslint docs 中阅读如何操作。如果您需要更多帮助,请发表评论。

      【讨论】:

      • 这是唯一的解决方案吗?然后,我将不得不忽略流类型目录中的每种类型,例如:SyntheticInputEventDispatch
      猜你喜欢
      • 2016-12-13
      • 2021-07-29
      • 2016-12-21
      • 2020-12-25
      • 2020-06-16
      • 2017-10-29
      • 2021-03-11
      • 2012-11-03
      相关资源
      最近更新 更多