Can anyone provide some guidance on working with interfaces in typescript?
I currently have the following 3 interfaces:
export interface HomeMenu {
[name: string]: MenuItem;
}
export interface MenuItem {
title: string;
route: string;
homeMenu?: HomeMenu;
}
export interface Menu {
homeMenu: HomeMenu;
}
Here is what I am trying to do:
var json: Menu = {
"homeMenu": {
"aname1": {
"title": "text",
"route": "myroute"
},
"aname2": {
"title": "text",
"route": "myroute",
"homeMenu": {
"aname21": {
"title": "text",
"route": "myroute"
},
"aname22": {
"title": "text",
"route": "myroute"
}
}
},
"aname3": {
"title": "text",
"route": "myroute"
}
}
}
json.homeMenu["aname2"].title = "myTitle";
However, I am having trouble adding a new item to the HomeMenu. I attempted to extend the HomeMenu interfaces with Array but received an error regarding index signature requirements. Arrays expect numerical indices, not strings
I have searched through Typescript documentation and various forums without finding a solution.
Is there another way to add a new item to the homeMenu object?
Any help would be greatly appreciated. Thank you.