【问题标题】:how to call an element which has '@' on it in typescript?如何在打字稿中调用带有“@”的元素?
【发布时间】:2021-11-12 17:31:05
【问题描述】:

我有这个API数据,是这样的

data = [{
 @type: "mobile",
 number: '02302030203'
  ...
 },
 ...
]

那么现在,我正在使用 react with typescript,所以我需要先声明元素才能访问它。

所以我的问题是,我应该如何在打字稿中声明@type,如下所示:

export interface DataTypes {
  number: number;
  @type: string; <---- how?
}

我该如何称呼它:

data[i].number

data[i].@type

【问题讨论】:

    标签: reactjs string typescript api types


    【解决方案1】:
    export interface DataTypes {
      number: number;
      "@type": string; <---- answer
    }
    
    data[i].['@type']
    

    在这里找到答案.. 无论如何谢谢 Typescript fields with special characters

    【讨论】:

      猜你喜欢
      • 2020-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-23
      • 1970-01-01
      • 2021-05-19
      • 2021-11-22
      • 2017-11-07
      相关资源
      最近更新 更多