typescript 接口(interface) : how to declare a property of Array type?

标签 typescript

我有以下界面:

export interface ITransaction {
   id: number;
   description: string;
   category: string;
   tags: array;
   date: string;
   amount: number;
}

显然我声明它是错误的,因为我在我的编辑器中看到一个错误。如您所见,标签应该是一个数组。这是 JSON 格式的数据:

{
   "id": 1,
   "description": "Sandwich",
   "date": "2017-09-01",
   "category": "Take away",
   "tags": ["Holidays"],
   "amount": -2
}

我似乎无法在文档中找到它。如何将此属性正确地放入界面中?

最佳答案

参见 TypeScript basic types :

export interface ITransaction {
  ...
  tags: string[]
  ...
}

关于 typescript 接口(interface) : how to declare a property of Array type?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46027652/

相关文章:

Angular/RxJS : keep interval running even in case of an error

node.js - 如何在 Typescript 中重新导入模块

node.js - 使用 typescript 将消息发送到特定 channel

javascript - React setState 不更新缩减数组

javascript - 如何创建对象数组或使用模型,就像我们在 JSON 中一样 - Angular/Ionic

javascript - 使用 cy.exec() 更改 Cypress 中的目录

image - ionic 3 : Print image using Bluetooth printer

angular - 如何从我的服务提供商的共享 HTTP 请求中捕获 401?

javascript - 如何通过@input 属性应用样式,我想增加 mat-autocomplete 的宽度

forms - 子组件的 Angular Form 验证