简体   繁体   English

类型“IntrinsicAttributes”上不存在属性“property”

[英]Property 'property' does not exist on type 'IntrinsicAttributes'

I'm a beginner to React Typescript.我是 React Typescript 的初学者。 I'm currently studying How to implement a Bar chart using Chart.js in React Typescript App.我目前正在研究如何在 React Typescript App 中使用 Chart.js 实现条形图。 So I just want to pass values of the property datasets: as a props to the BarChart.tsx component.所以我只想将属性datasets:作为道具传递给 BarChart.tsx 组件。

So here is my BarChart.tsx component:所以这是我的 BarChart.tsx 组件:

import Chart from 'chart.js/auto';
import { Line } from 'react-chartjs-2';
import 'chartjs-adapter-luxon';
import StreamingPlugin from 'chartjs-plugin-streaming';

Chart.register(StreamingPlugin);

interface ChartProperty {
  label: string;
  backgroundColor: string;
  borderColor: string;
  borderDash?: number[];
  cubicInterpolationMode?: string;
  fill: boolean;
  data: [];
}

interface Props {
  property: ChartProperty[];
}

const BarChart: React.FC<Props> = ({property}) => {
  return (
    <div>
      <Line
        data={{
          datasets: property,
        }}
        height={100}
        width={400}
        options={{
          scales: {
            x: {
              type: 'realtime',
              realtime: {
                delay: 2000,
                onRefresh: (chart) => {
                  chart.data.datasets.forEach((dataset) => {
                    dataset.data.push({
                      x: Date.now(),
                      y: Math.random(),
                    });
                  });
                },
              },
            },
          },
        }}
      />
    </div>
  );
};

export default BarChart;

And here is my App.tsx component:这是我的 App.tsx 组件:

import './App.css';
import BarChart from './components/BarChart';

const ChartProperty = [
  {
    label: 'Dataset 1',
    backgroundColor: 'rgba(255, 99, 132, 0.5)',
    borderColor: 'rgb(255, 99, 132)',
    borderDash: [8, 4],
    fill: false,
    data: [],
  },
  {
    label: 'Dataset 2',
    backgroundColor: 'rgba(54, 162, 235, 0.5)',
    borderColor: 'rgb(54, 162, 235)',
    cubicInterpolationMode: 'monotone',
    fill: false,
    data: [],
  },
];

const App = () => {
  return (
    <div>
      <h1 style={{ textAlign: 'center' }}>Sample Bar Chart</h1>
      <BarChart property={ChartProperty} />
    </div>
  );
};

export default App;

But here when I'm trying this I'm getting error in <BarChart property={ChartProperty} /> in prop named property .但是在这里,当我尝试这个时,我在名为property的 prop 中的<BarChart property={ChartProperty} />中遇到错误。 So here is the error I'm getting:所以这是我得到的错误:

TS2322: Type '{ property: ({ label: string; backgroundColor: string; borderColor: string; borderDash: number[]; fill: boolean; data: never[]; cubicInterpolationMode?: undefined; } | { label: string; backgroundColor: string; ... 4 more ...; borderDash?: undefined; })[]; }' is not assignable to type 'IntrinsicAttributes'.
  Property 'property' does not exist on type 'IntrinsicAttributes'.
    25 |     <div>
    26 |       <h1 style={{ textAlign: 'center' }}>Sample Bar Chart</h1>        
  > 27 |       <BarChart property={ChartProperty} />
       |                 ^^^^^^^^
    28 |     </div>
    29 |   );
    30 | };

Can someone help me in this case?在这种情况下有人可以帮助我吗? I'm really appreciate if someone can show my error.Thank you in advance.如果有人能显示我的错误,我真的很感激。提前谢谢你。

You can't write like this: data: [];你不能这样写: data: []; . . Correct: data: any[]正确: data: any[]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 属性…在类型&#39;IntrinsicAttributes&…&#39;上不存在 - Property … does not exist on type 'IntrinsicAttributes & …' 属性..在类型“IntrinsicAttributes &amp;..”上不存在 - Property .. does not exist on type 'IntrinsicAttributes & ..' React-类型IntrinsicAttributes上不存在属性 - React - Property does not exist on type IntrinsicAttributes 属性“ title”在类型“ IntrinsicAttributes&IProps”上不存在 - Property 'title' does not exist on type 'IntrinsicAttributes & IProps' “IntrinsicAttributes”类型上不存在模态属性“show” - Modal Property 'show' does not exist on type 'IntrinsicAttributes' 属性不存在于类型 'IntrinsicAttributes & { children?: ReactNode; }' - Property does not exist on type 'IntrinsicAttributes & { children?: ReactNode; }' 类型“IntrinsicAttributes &amp; InferPropsInner”上不存在属性“X” - Property 'X' does not exist on type 'IntrinsicAttributes & InferPropsInner 类型 IntrinsicAttributes 和字符串 [] 上不存在属性“道具” - Property 'props' does not exist on type IntrinsicAttributes & string[] “IntrinsicAttributes &amp; CustomComponentProps”类型上不存在属性“prop” - Property 'prop' does not exist on type 'IntrinsicAttributes & CustomComponentProps' “IntrinsicAttributes &amp; AutocompleteProps”类型上不存在属性“limitTags” - Property 'limitTags' does not exist on type 'IntrinsicAttributes & AutocompleteProps
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM