当我尝试运行下面的组件时,它在我的声明中显示了类型问题

下面是我得到的问题类型'{ First: string[];Second: string[];Third: string[];Four: string[];}‘缺少’any[]‘类型的以下属性:长度、弹出、推送、连接和28个以上。TS2740

接口标头声明我已经尝试了标头data any,String,Array,但都不起作用

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

常量标头数据声明

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>  
}

主要组件类

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

转载请注明出处:http://www.lntyys.com/article/20230328/932923.html

随机推荐

  1. 在TypeScript中扩展与实现纯抽象类

    假设我有一个纯抽象类(即没有任何实现的抽象类): abstract class A { abstract m(): void; } 像在C#和Java中一样,我可以扩展抽象类: c...

  2. 为Typescript中的其他属性编制索引的属性

    我有以下类型:interface CellsReducer { source: number; destination: number; plan: string; duration: number; ...

  3. 在typescript中键入具有联合返回类型的递归函数

    我正在尝试键入一个typescript函数,该函数向任意深度的嵌套数组中的对象添加属性。运行时代码在Javascript中是微不足道的,但我已经花了一整天的时间来编译Typescript类型。代码应采用类似于此[{}, {}]或此[[{},...

  4. Typescript - const声明中缺少初始值设定项

    我有以下代码。获取错误SyntaxError:常量声明中缺少初始值设定项const manufacturers: any[] = []; console.log(Available Products are: ); for ...

  5. 关于TypeScript中import JSON的正确姿势详解

    前言 Typescript是微软内部出品的,用actionscript的语法在写js的一门新语言,最近 TypeScript 中毒,想想我一个弱类型出身的人,怎么就喜欢上了类型约束……当然这不是重点,重点可能还是 JS 没有接口,我没法靠...

  6. 从typescript中的函数参数推断类型参数

    我有this playground和下面的代码export interface RemoteMethodsR { getAll: (url: string) = PromiseR; create: (url: string, mod...

  7. TypeScript中是否有类似于`keyof`的`valueof`?

    我希望能够将给定键和值作为输入的值分配给对象属性,但仍然能够确定值的类型。解释起来有点困难,因此这段代码应该可以揭示问题: type JWT = { id: string, token: string, expire: Date }; c...

  8. 为什么typescript中的“readonly”属性不起作用?

    interface ReadExample { readonly book_id: number, book_name: string } class Book implements ReadExample{ bo...

  9. 从typescript中的数组中删除具有特定值的元素

    我有这个: nominees: Array{ id: number, title: string, company: string, category: string };复制我想删除基于id的元素,例如,如果给定的id是10,那么我想...

  10. TypeScript中导入对象的模拟函数

    我有一个导出两个对象(由Typegoose创建)的TypeScript文件。// my-document.ts export class MyDocument extends Typegoose { // ... } export c...