React-typescript chart.js 错误类型中缺少“类型”

问题描述

我是一个学习打字稿,最近从 React 迁移过来,我在我的 react-typescript 项目中使用图表 js 来绘制一些图表,几个小时后我收到了这个错误

Property 'type' is missing in type '{ data: { labels: string[]; datasets: { label: string; data: number[]; fill: boolean; backgroundColor: string; borderColor: string; }[]; }; options: { scales: { yAxes: { ticks: { beginAtZero: boolean; }; }[]; }; }; }' but required in type 'Props'

enter image description here

如果有人能在这里帮助我就好了 谢谢

解决方法

即使 react-chartjs-2 不期望 Line 组件的类型 props 并且它的值默认分配给 line,使用的接口具有类型 props按要求。请找到接口here

请将类型属性传递给链接标签。

<line type='line' data={data} />