簡體   English   中英

flowtype 覆蓋率報告沒有選擇我已經定義的類型

[英]flowtype coverage report is not picking up types I have already defined

我正在逐步將 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.xxjs存在。

$ 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;
  ...
}

感謝您閱讀本文。 干杯。

  1. 不知道你是否應該有flow-typed/npm/react-bootstrap_vx.xxjs 這看起來像一個存根,可能與 0.32.0 沖突? 您可能想要刪除它,它應該解決沒有得到任何類型覆蓋的問題。
  2. 第 8 行沒有得到正確的類型可能是因為您將模塊聲明為@fontawesome/react-fontawesome而不是@fortawesome/react-fontawesome
  3. 這和4.可能有關。 看起來你的語法有點不對勁,不確定它是否是因為試圖簡化你的例子。 例如,我不確定為什么要將EditorContextualProps傳播到自身中,盡管您可以使用 class OrderItem作為類型,但 class 的語法使用半類型和半 ZA2F2ED4F8EBC2CBB4C21A29DC40AB61 語法。

如果您可以稍微改進您的示例或更新您的問題以包含嘗試流程,它可以幫助描繪出更好的畫面。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM