I have defined the interface in a d.ts file:
declare module myModule
{
interface IQedModel {
field: string | string[];
operator: string;
}
}
In an anuglar controller I have implemented it:
vm.filters = <myModule.IQedModel>{
operator: 'and',
field: []
};
function populateFields() {
vm.filters.field = [];
angular.forEach(addedFilters, item => {
vm.filters.field.push(item.data); //<-- THIS LINE SHOWS ERRORS
});
}
The error is:
Property 'push' does not exist on type 'string | string[]'
What is the issue here?
(vm.filters.field as string[]).push(...)<myModule.IQedModel>on the assignment tovm.filtersthe compiler will infer the array and will not complain. (the assignment within thepopulateFieldsfunction is unnecessary)