Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Initialise empty object array in TypeScript

How to initialise empty object array in TypeScript?

Code:

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

Compilation error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 }> = [];

Alternatively:

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading