【问题标题】:How to set up Flow type declarations - lint up with error "not defined"?如何设置流类型声明 - 错误“未定义”?
【发布时间】:2017-08-16 08:58:23
【问题描述】:

我刚开始使用类型化 JS,目前只是导出/导入我的类型。在查找了一些东西之后,我认为正确的解决方案似乎是“声明”的想法。

阅读 [https://flowtype.org/docs/declarations.html#pointing-your-project-to-declarations] 后,我尝试了“.flowconfig”样式。

decls/types.js

declare type Post = {
  feed: Connection,
}

declare type Connection = {
  edges: Array<Edge>,
  pageInfo: PageInfo,
}

declare type Edge = {
  cursor: number,
  node: Node,
}

declare type PageInfo = {
  endCursor: number,
  hasNextPage: boolean,
}

declare type Node = {
  id: string,
  createdAt: number,
}

然后我将decls/ 目录添加到我的.flowconfig [libs]

.flowconfig

[libs]
node_modules/react-native/Libraries/react-native/react-native-interface.js
node_modules/react-native/flow
flow/
decls/

但是,所有类型都会出现未定义的错误,例如“连接”未定义。

我错过了什么吗?

【问题讨论】:

  • 你在使用 ESLint 吗?

标签: reactjs eslint flowtype


【解决方案1】:

由于您使用的是 ESLint,因此您需要添加 eslint-plugin-flowtype 扩展并至少启用 define-flow-type 规则,以便 ESLint 不会将流类型标记为未定义。

ESLint 配置:

{
  "plugins": [
    "flowtype"
  ],
  "rules": {
    "flowtype/define-flow-type": 2
  }
}

【讨论】:

  • 是的,就是这样!如果您将它们放在同一个文件中,则不会考虑定义类型,而不是考虑似乎需要插件/规则的声明。我相信在安装插件后我还必须重新启动 Atom。非常感谢!
猜你喜欢
  • 1970-01-01
  • 2017-10-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-07
相关资源
最近更新 更多