将我的 react es6 comp 转换为 typescript 时,我在 IDE 的第 16 行(<Line ...)上遇到了这个奇怪的 typescript 错误。它是我使用 react-chartjs-2 的图表组件。
类型'{数据:{标签:字符串[];中缺少属性'类型';数据集:{标签:字符串;数据:字符串[];}[]; }; 高度:数字;宽度:数字;选项:{维护AspectRatio:布尔值;尺度:{ yAxes:{ 刻度:{ beginAtZero:布尔值;}; }[]; }; 传奇: { ...; }; }; }' 但在“道具”类型中是必需的。
import React from "react";
import { Line, defaults } from "react-chartjs-2";
defaults.plugins.tooltip.enabled = true;
defaults.plugins.legend.position = "bottom";
interface Props {
currencyValues: string[],
dateList: string[],
}
const LineGraph = ({ currencyValues, dateList }: Props) => {
return (
<div className="graphContainer">
{currencyValues.length ? (
<Line
data={{
labels: [...dateList],
datasets: [
{
label: "Historical Dates",
data: [...currencyValues],
},
],
}}
height={400}
width={600}
options={{
maintainAspectRatio: false,
scales: {
yAxes: [
{
ticks: {
beginAtZero: true,
},
},
],
},
legend: {
labels: {
fontSize: 25,
},
},
}}
/>
) : null}
</div>
);
};
export default LineGraph;