【问题标题】:flowtype coverage report is not picking up types I have already definedflowtype 覆盖率报告没有选择我已经定义的类型
【发布时间】:2020-08-08 01:57:55
【问题描述】:

我正在逐步将 flowtype 引入我们的 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 存在。

$ 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] 部分中使用。

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如下:

$ 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 中定义如下:
export type EditorContextualProps = {|
  orderItem: OrderItem,
  zoomLevel: ZoomLevel,
  ...EditorContextualProps,
  ...OrderItemEditCallbacks,
  ...PhotoEditCallbacks,
  handleCloseModal: () => void
|};

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

export default class OrderItem {
  id: string;
  product: string;
  size: string;
  props: { [string]: ?string };
  options: Array<string>;
  quantity: number;
  photos: Array<Photo>;
  subtotal: string;
  ...
}

感谢您阅读本文。干杯。

【问题讨论】:

    标签: javascript flowtype flow-typed


    【解决方案1】:
    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 类作为类型,但该类的语法是使用半类型和半类语法。

    如果您可以稍微改进您的示例或更新您的问题以包含try flow,它可以帮助描绘出更好的画面。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-29
      • 2017-10-03
      • 1970-01-01
      • 2016-03-21
      • 2020-05-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多