简体   繁体   English

打字稿中声明部分的类型错误(Angular/React)

[英]Type error in declaration part in typescript (Angular/React)

When i tried run the below component it showing type issue in my declartion当我尝试运行以下组件时,它在我的声明中显示类型问题

Below is the issue what i am getting Type '{ First: string[];下面是我遇到的问题 Type '{ First: string[]; Second: string[];第二个:字符串[]; Third: string[];第三个:string[]; Four: string[];四:string[]; }' is missing the following properties from type 'any[]': length, pop, push, concat, and 28 more. }' 缺少类型 'any[]' 中的以下属性:length、pop、push、concat 和 28 个其他属性。 TS2740 TS2740

Interface headers declartion I have tried the headers data any,String,Array but it was not working接口标头声明我已经尝试过标头数据 any,String,Array 但它不起作用

   interface headers { 
    First: any[], 
    Second: any[],  
    Third: any[], 
    Four:any[],   
}

const headers data declartion const 标头数据声明

const headers = {
      First: [
        'lara',
         'dravid',
         'sachin',
        'Ganguly',
      ],
      Second: [
       'kohli',
         'dhoni',
         'smith',
        'kane',
      ],
      Third: [
        'lee',
         'mustaq',
         'vaas',
        'shane',
      ],
      Four: [
       'bumrah',
         'starc',
         'jadeja',
        'shami',
      ],
    };  


Export state 
export interface State {  
    headersList: Array<any>  
}

Main component class主要组件类

export  class MyComp extends React.PureComponent<Props, State> {
  constructor(props) {
    super(props);
    this.state = { 
        headersList: headers, 
    };
this.state = { 
    headersList: [headers], 
};

Will fix the problem会解决问题

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM