我设置了以下选项:
export const options = {
responsive: true,
scales: {
x: {
ticks: {
maxTicksLimit: 10,
autoSkip: true,
color: 'white',
},
type: 'time',
adapters: {
date: {
locale: enGB,
},
},
},
y: {
ticks: {
color: 'white',
},
},
},
plugins: {
legend: {
display: false,
},
title: {
display: true,
text: 'IndexCoin Price',
color: 'white',
},
},
}
然后我在
<Line options={options} data={dataSets} />
在这一行中,vscode红色下划线表示出现问题的第一个选项:
"min" | "max"> & { min: string | number; max: string | number; suggestedMin: string | number; ... 4 more ...; ticks: { ...; }; }> | ... 4 more ... | undefined'.
Type '{ ticks: { maxTicksLimit: number; autoSkip: boolean; color: string; }; type: string; adapters: { date: { locale: Locale; }; }; }' is not assignable to type '_DeepPartialObject<{ type: "timeseries"; } & Omit<CartesianScaleOptions, "min" | "max"> & { min: string | number; max: string | number; suggestedMin: string | number; ... 4 more ...; ticks: { ...; }; }>'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"timeseries"'.ts(2322)
types.d.ts(19, 5): The expected type comes from property 'options' which is declared here on type 'IntrinsicAttributes & Omit<ChartProps<"line", number[], Date>, "type"> & { ref?: ForwardedRef<ChartJSOrUndefined<"line", number[], Date>> | undefined; }'
如果我在选项中删除type: 'time'
,这个问题就会消失。尽管代码工作正常。为什么会发生这种情况?
1条答案
按热度按时间yzuktlbb1#
显式设置类型应该可以消除类型错误。
有关更多信息,请查看react-chartjs-2 docs中的常见问题解答。