I am searching for a solution to properly enforce strong typing in the following scenario. I believe Typescript Generics might be the way to go here.
interface Person {
name: string;
age: number;
}
const person: Person = {
name: "John",
age: 30,
};
const modifyPerson = (key: keyof Person, value) => {
person[key] = value;
}
My goal is for the 'modifyPerson' function to only accept keys from the Person interface as its first argument, and then based on that key, determine what type of value can be assigned to it.
Could you provide an example of how this can be achieved? Thank you!