【发布时间】:2020-12-31 07:40:57
【问题描述】:
我有一个像这样的对象类型:
interface DataType {
labels: string[];
datasets: {
[key: string]: number[]
};
}
我试图将它的 prop-type 定义为:
data: PropTypes.objectOf(
PropTypes.exact({
labels: PropTypes.arrayOf(PropTypes.string).isRequired,
datasets: PropTypes.objectOf(
PropTypes.shape({
data: PropTypes.arrayOf(PropTypes.number),
})
)
})
).isRequired,
但我收到此错误:
(property) data?: Validator<DataType> | undefined
Type 'Validator<{ [x: string]: Required<InferProps<{ labels: Validator<(string | null | undefined)
[]>; datasets: Requireable<{ [x: string]: InferProps<{ data: Requireable<(number | null | undefined)
[]>; }> | null | undefined; }>; }>> | null | undefined; }>' is not assignable to type
'Validator<DataType>'.
Type '{ [x: string]: Required<InferProps<{ labels: Validator<(string | null | undefined)[]>;
datasets: Requireable<{ [x: string]: InferProps<{ data: Requireable<(number | null | undefined)[]>;
}> | null | undefined; }>; }>> | null | undefined; }' is missing the following properties from type
'DataType': labels, datasets ts(2322)
谁能帮我解决这个问题。
【问题讨论】:
标签: reactjs typescript react-props