Initialise empty object array in TypeScript

How to initialise empty object array in TypeScript?


let data: [{productID: number, vendorID: number}] = [];

Compilation error:

Type '[]' is not assignable to type '[{productID: number, vendorID: number}]'.

>Solution :

The format you have written is a tuple with one-element, try this instead:

let data: Array<{ productID: number, vendorID: number }> = [];


let data: { productID: number; vendorID: number }[] = [];

Leave a Reply