Working on my project using Angular and TypeScript includes defining an array that can contain arrays or objects.
public arrangedFooterMenu: IMenuItemType[][] | IMenuItemType[] = [];
typesOfData.forEach(type => {
let filteredData: IMenuItemType | IMenuItemType[];
filteredData = data.filter(el => {
return el.Type === type;
});
if (filteredData.length > 1) {
this.arrangedFooterMenu.push(filteredData as IMenuItemType & IMenuItemType[]);
} else {
// encountering error in the else section
this.arrangedFooterMenu.push(...filteredData);
}
});
An error occurs in the else section with the filtered data, presenting the following message: TS2345: Argument of type 'IMenuItemType' is not assignable to parameter of type 'IMenuItemType & IMenuItemType[]'.