繁体   English   中英

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忽略列表的方式。 实际上它是由eslint-plugin-flowtype处理的,我已经安装了但是我并没有扩展它:

.eslintrc

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM