I am working with two interfaces
export interface ClosureItem{
id:string;
name:string;
visibility?:boolean;
}
export interface ClosureAllItems{
[K:string]:ClosureItem;
Financials:ClosureItem;
Risk:ClosureItem;
Issue:ClosureItem;
AR2:ClosureItem;
}
Every time I attempt to assign a value to the properties, an error message pops up saying
Cannot set properties of undefined (setting 'key')
This is how my code is structured
myClosureItems!:ClosureAllItems;
constructor(){}
....
....
setitems(){
let k:string[]=["Financials","AR2","Risk","Issue"];
k.forEach(element=>{
this.myClosureItems[element]={id:element,name:element,visibility:true}
});
}
*In the second interface, I have specified K:string to prevent index issues when using string names