In js I have a function which modify properties of an object contained in a list of object according to parameters:
function edit(object, key, property, value){
object[key][property] = value;
}
How would I manage to do the same function in TypeScript ?
From now I've made this:
function edit(object: ObjectList, key: string, property: string, value: number){
object[key][property] = value;
}
But that doesn't work and gives me a Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ name: string; mastery: number; parent_skill: number; access_level: number; cost: string; cost_value: number; background_color: number[]; font_color: number[]; description: string; required_skills: number[]; }'. No index signature with a parameter of type 'string' was found on type '{ name: string; mastery: number; parent_skill: number; access_level: number; cost: string; cost_value: number; background_color: number[]; font_color: number[]; description: string; required_skills: number[]; }'
I want to be able to call the function like this:
edit(myObject, "first", "oneProperty", "newValue1");
And the result would be that my "first" item in myObject would have "newValue1" for its "oneProperty" property.
More informations: My object list
type SkillList = {
[key: string]: Skill;
};
My object
type Skill = {
name: string;
mastery: number;
parent_skill: number;
access_level: number;
cost: string;
cost_value: number;
background_color: number[];
font_color: number[];
description: string;
required_skills: number[];
};
ObjectListhave?Skill, but I deleted the comment because I thought it would make more sense to wait for someone more competent in TypeScript than me to write an answer.