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 []'.
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 ).
typescript, , :
let a: Array<number>;
let a: number[];
:
let a: [number];
, .:
let a: [number, string, string];
, , , , tags locations, 0, 1.
tags
locations
Tag[], TypeScript, Tag.
Tag[]
Tag
export class TagCloud { tags: Tag[]; locations: Location[]; constructor() { // TS already knows the type this.tags = [] this.locations =[] } }
Source: https://habr.com/ru/post/1661954/More articles:How to convert timedelta to string and vice versa - pythonАутентификация пользователя при нажатии уведомления о просмотре чата - iosPHP-DI injectOn does not inject on setter methods - phpSpeed to repeat several times over the generator compared to the list - performanceWhat does the "On" prefix implement in case of cases in C # coding? - c #Развертывание докеров Heroku - ruby-on-railsGraphQL type mapping for PostgresQL - typesmodule.js 474 throw err - javascriptBuild a list of lists from the command line - pythonHow to configure Allure Jenkins plugin? - allureAll Articles