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

I have a piece of code, for example:

export class TagCloud {

    tags: [Tag];
    locations: [Location];

    constructor() {
        this.tags = new Array<Tag>();
        this.locations = new Array<Location>();
    }
}

But this gives me the following errors:

error TS2322: Type 'Tag []' cannot be assigned to type '[Tag]'. Property '0' is not in type 'Tag []'.

error TS2322: Type 'Location []' cannot be assigned to type '[Lo cation]. Property '0' is not in type 'Location []'.

What am I doing wrong (code works though)?

I am using typing with es6-shim descriptions ( https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/es6-shim ).

+4
2

typescript, , :

let a: Array<number>;

let a: number[];

:

let a: [number];

, .
:

let a: [number, string, string];

, , , , tags locations, 0, 1.

+5

Tag[], TypeScript, Tag.

export class TagCloud {

    tags: Tag[];
    locations: Location[];

    constructor() {
        // TS already knows the type
        this.tags = []
        this.locations =[]
    }
}
0

Source: https://habr.com/ru/post/1661954/


All Articles