Error TS2322: Type 'Object[]' is not assignable to type '[Object]' Error TS2322: Type 'Object[]' is not assignable to type '[Object]' typescript typescript

Error TS2322: Type 'Object[]' is not assignable to type '[Object]'


In typescript when you declare an array you either do:

let a: Array<number>;

or

let a: number[];

When you use:

let a: [number];

you are in fact declaring a tuple, in this case of length one with number.
This is another tuple:

let a: [number, string, string];

The reason you get this error is because the length of the array you assign to tags and locations are 0, and it should be 1.


You want to use Tag[] to tell TypeScript you are declaring an array of Tag.

export class TagCloud {    tags: Tag[];    locations: Location[];    constructor() {        // TS already knows the type        this.tags = []        this.locations =[]    }}