I'm working with a nested JSON object and defining an interface for it.
interface Menu {
[key: string]: string[] | Menu;
}
const menuRoles: Menu = {
site: {
only: [],
category: {
only: ['manager', 'head', 'lead'],
},
'floor-section': {
only: ['head', 'lead'],
},
},
};
However, when I try to use it, a warning appears.
const menuPermissionForKey = menuRoles.site || { only: [] };
const rolesCanAccessMenu = menuPermissionForKey.only || [];
▔▔▔▔
any
Property 'only' does not exist on type 'Menu | string[]'.
Property 'only' does not exist on type 'string[]'
What am I doing wrong or what am I missing?