首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >流类型覆盖率报告没有选择我已经定义的类型。

流类型覆盖率报告没有选择我已经定义的类型。
EN

Stack Overflow用户
提问于 2020-08-08 01:57:55
回答 1查看 169关注 0票数 0

我正在逐步将base类型引入我们的react/es7代码库。

运行flow不再会产生错误,这是非常好的。但我很困惑为什么某些台词没有被覆盖。

这是flow coverage --json的输出。屏幕截图捕捉了一些常见的报道问题。

1.流类型已经覆盖的类型仍然没有被使用(第6行):我有flow-typed install react-bootstrap,我可以确认./flow-typed/npm/react-bootstrap_v0.32.x.js./flow-typed/npm/react-boothstrap_vx.x.x.js的存在。

代码语言:javascript
复制
$ fd react-bootstrap ./flow-typed
flow-typed/npm/react-bootstrap_v0.32.x.js
flow-typed/npm/react-bootstrap_vx.x.x.js

2.自定义库定义文件不被拾取(第8-9行):.我添加了以下定义文件,并确保它在.flowconfig[libs]部分中使用。

代码语言:javascript
复制
declare module "@fortawesome/fontawesome-common-types" {
  declare type IconDefinition = { icon: Array<mixed> };
}

declare module "@fontawesome/react-fontawesome" {
  import type { IconDefinition } from "@fortawesome/fontawesome-common-types";
  import type { Component } from "react";
  declare export class FontAwesomeIcon extends React$Component<{
    icon: IconDefinition,
    ...
  }> {}
}

我的.flowconfig如下:

代码语言:javascript
复制
$ cat .flowconfig
[lints]
all=warn

[include]
frontend

[ignore]
# Run `flow ls` to get a list of all files visible to flow
.*/frontend/admin/.*

[libs]
flow-typed
node_modules/fbjs/flow/lib
frontend/types

[untyped]

[options]
module.file_ext=.js
module.file_ext=.jsx
module.system.node.allow_root_relative=true
module.system.node.root_relative_dirname=./frontend
log.file=/tmp/flowtype.log
esproposal.decorators=ignore

# Flowtype doesn't support using css in jsx.
# https://gist.github.com/lambdahands/d19e0da96285b749f0ef
module.name_mapper='.*\(.css\)' -> 'empty/object'
  1. 未识别的自定义类型(第16和#20行)EditorContextualProps已在editor/types.jsx中定义如下:
代码语言:javascript
复制
export type EditorContextualProps = {|
  orderItem: OrderItem,
  zoomLevel: ZoomLevel,
  ...EditorContextualProps,
  ...OrderItemEditCallbacks,
  ...PhotoEditCallbacks,
  handleCloseModal: () => void
|};

4.未使用其他文件中定义的类(第27行)orderItem: OrderItem已在名为order_item.js的文件中定义,如下所示:

代码语言:javascript
复制
export default class OrderItem {
  id: string;
  product: string;
  size: string;
  props: { [string]: ?string };
  options: Array<string>;
  quantity: number;
  photos: Array<Photo>;
  subtotal: string;
  ...
}

谢谢你读了这么多。干杯。

EN

回答 1

Stack Overflow用户

发布于 2020-08-30 03:49:41

  1. 不知道你是否应该拥有flow-typed/npm/react-bootstrap_vx.x.x.js。这看起来像一个存根,它可能与0.32.0冲突吗?您可能想要删除这一点,它应该解决没有得到任何类型的覆盖。
  2. 第8行没有得到正确的类型可能是因为您已经将模块声明为,@fontawesome/react-fontawesome而不是@fortawesome/react-fontawesome
  3. 这与4.可能有关。看起来您的语法有点过时,不确定它是否是试图简化示例的结果。例如,我不知道为什么要将EditorContextualProps扩展到自身,尽管可以使用类OrderItem作为类型,但类的语法是使用半类型和半类语法。

如果您能够稍微细化示例或更新您的问题以包含试流,那么它可以帮助您绘制出更好的画面。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63311107

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档