微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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} />

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。