I've created a "load" function that will take a JSON format of data and load the attributes into properties of my class. I'm trying to use typescript for the first time and have managed to fix most errors, however there are some I can't work out.
load(id): void{
let item:object = this.items.find(item => item.id == id);
if(typeof(item) != 'undefined'){
for(let k in item){
if(item.hasOwnProperty(k)){
this[k] = item[k];
}
}
}
}
This gives the following error:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'.
No index signature with a parameter of type 'string' was found on type '{}'.
386 | for(let k in item){
387 | if(item.hasOwnProperty(k)){
> 388 | this[k] = item[k];
| ^
389 | }
390 | }
391 | }
How would I go about fixing this? Is the issue with the pattern that I am using, or can I just declare the types differently to stop the error showing up?