[英]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'
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;
...
}
感謝您閱讀本文。 干杯。
flow-typed/npm/react-bootstrap_vx.xxjs
。 這看起來像一個存根,可能與 0.32.0 沖突? 您可能想要刪除它,它應該解決沒有得到任何類型覆蓋的問題。@fontawesome/react-fontawesome
而不是@fortawesome/react-fontawesome
。EditorContextualProps
傳播到自身中,盡管您可以使用 class OrderItem
作為類型,但 class 的語法使用半類型和半 ZA2F2ED4F8EBC2CBB4C21A29DC40AB61 語法。如果您可以稍微改進您的示例或更新您的問題以包含嘗試流程,它可以幫助描繪出更好的畫面。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.