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

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

类型“{数据:{标签:字符串[]中缺少属性“类型”;数据集:{ 标签:字符串;数据:字符串[]; }[]; };高度:数字;宽度:数字;选项:{ maintainAspectRatio: bool 值;尺度:{ yAxes:{ 刻度:{ beginAtZero: bool 值; }; }[]; };传奇: { ...; }; }; }' 但在类型 '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 Prop 是强制性的。这似乎是图书馆作者的一个错误,在 github 上有多个 Unresolved 问题(1,2)

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

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

关于reactjs - 属性 'type' 在类型中缺失。但在类型 'Props' 中是必需的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67376849/

相关文章:

c++ - 指向结构成员?

arrays - 将字符串添加到空数组给出 `NAN`

ruby - "+1"给我的结果与 ruby​​ 中的 "+ 1"不同?

flutter - 类型错误 : Cannot read property 'isSupported

swift - 类名可以与 Swift 中的协议(protocol)名相同吗?

node.js - 如何从 bull js 中删除延迟的工作?

c++ - 我可以在没有默认初始化的情况下初始化数组的 std::unique_ptr (我只想让它

amazon-ec2 - Tensorflow 安装在 AWS ec2 实例上终止

r - 如何将经过训练和测试的随机森林模型应用于 tidymodels 中的新数据集?

git - 无法访问 'https://github.com/Homebrew/brew/' : L