Flow - 如何在另一种类型中使用声明的类型?
Flow - how to use declared type in another type?
import type {crusherDowntimeRecord} from "./downtime/types";
type Props = {
data: Array<crusherDowntimeRecord>,
};
type State = {
rows: Props.data,
};
在 Props.data
流抛出:
Error:(30, 15) Cannot get Props.data because property data is missing in Props [1].
怎么了?
您无法通过 Props
访问 data
,因为它是 type
,而不是 javascript object
。
对于解决方案,请使用 flow $PropertyType
:
import type {CrusherDowntimeRecord} from "./downtime/types";
type Props = {
data: Array<CrusherDowntimeRecord>,
};
type State = {
rows: $PropertyType<Props, 'data'>,
};
import type {crusherDowntimeRecord} from "./downtime/types";
type Props = {
data: Array<crusherDowntimeRecord>,
};
type State = {
rows: Props.data,
};
在 Props.data
流抛出:
Error:(30, 15) Cannot get Props.data because property data is missing in Props [1].
怎么了?
您无法通过 Props
访问 data
,因为它是 type
,而不是 javascript object
。
对于解决方案,请使用 flow $PropertyType
:
import type {CrusherDowntimeRecord} from "./downtime/types";
type Props = {
data: Array<CrusherDowntimeRecord>,
};
type State = {
rows: $PropertyType<Props, 'data'>,
};