Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript interface: how to declare a property of Array type?

Tags:

typescript

I have the following interface:

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

Obviously I'm declaring it wrong as I'm seeing an error in my editor. As you can see, tags ought to be an array. This is how the data look in JSON format:

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

I can't seem to find this in the docs. How can I put this property correctly into the interface?

like image 531
Martyn Avatar asked Dec 18 '22 04:12

Martyn


1 Answers

See TypeScript basic types:

export interface ITransaction {
  ...
  tags: string[]
  ...
}
like image 124
Harald Gliebe Avatar answered Mar 04 '23 12:03

Harald Gliebe