Assuming I have an interface like:
interface Foo {
description: string;
amount: number;
}
And a function to update Foo like:
public updateFoo(key: keyof Foo, val: string | number): void {
this.foo = { ...foo, [key]: val }
}
When I call this function in TypeScript, this is obviously considered valid:
this.updateFoo('description', 10)
Is there a way for TypeScript to use the keys that it already knows belong to the target interface and validate the type of the second argument being passed?