【发布时间】: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'
-
无法识别自定义类型(第 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