属性 'type' 在类型中缺失。但在类型 'Props' 中是必需的

Property 'type' is missing in type .but required in type 'Props'

在将我的 react es6 comp 转换为 typescript 时,第 16 行(

属性 'type' 在类型 '{ data: { labels: string[]; 中缺失数据集:{ 标签:字符串;数据:字符串[]; }[]; };高度:数字;宽度:数字;选项:{ maintainAspectRatio:布尔值;尺度:{ yAxes:{ 刻度:{ beginAtZero:布尔值; }; }[]; };传奇: { ...; }; }; }' 但在 'Props'.

类型中是必需的
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;

看起来类型定义说 type 道具是强制性的。这似乎是图书馆作者的一个错误,在 github (1, 2)

上有多个未解决的问题

如果你传入一个type prop,它将消除类型错误,并且没有任何效果(因为Line组件overwrites type prop):

<Line
  type="line"
  data={{
    //etc