These are the Interface definitions that I currently have:
interface IComponents {
root: IComponent,
[key: string]: IComponent,
}
interface IComponent {
type: string,
children?: Array<keyof IComponents>;
}
I need to restrict the "children" property of components to only accept keys that are defined Components. For example, in the case of the "root.children" property, it should only accept the keys root, button1, and button2:
const list: IComponents = {
root: {
type: 'panel',
children: ['button1', 'button2', 'button3']
},
button1: {
type: 'button'
},
button2: {
type: 'button'
},
}
Currently, the code allows arbitrary strings like "button3" which is not desirable.