小编mad*_*oka的帖子

无法在react-chartjs-2中分配类型

我正在使用反应和打字稿。我收到类型错误。我该如何解决?

位置是字符串类型。 http://www.chartjs.org/docs/latest/configuration/legend.html

[反应+ts+react-chartjs-2]

import React from 'react';
import {Pie} from 'react-chartjs-2';

export default class Chart extends React.Component{
  constructor(props) {
     super(props);
     this.state = { };
  }

  render() {
    let options = {
      legend: {
        position:'bottom',
      }
    };

    return (
      <Pie options={options}  />
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

[错误。] 属性“选项”的类型不兼容。

Type '{ legend: { position: string; }; }' is not assignable to type 'ChartOptions'.
Types of property 'legend' are incompatible.
Type '{ position: string; }' is not assignable to type 'ChartLegendOptions'.
Types of …
Run Code Online (Sandbox Code Playgroud)

javascript typescript reactjs chart.js react-chartjs

4
推荐指数
1
解决办法
7789
查看次数