ESLint 报告流类型全局类型的 no-undef 错误

ESLint reports no-undef error on flow-typed global types

我在 /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 这些类型确实声明​​为全局的?或者我应该将它们添加到某个忽略列表中吗?

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

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

.eslintrc

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