TypeScript接口:如何声明Array类型的属性?

时间:2017-09-03 20:40:46

标签: 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
}

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

1 个答案:

答案 0 :(得分:7)

请参阅TypeScript basic types

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