Apologies for the lack of a suitable title, this question is quite unique.
I am interested in creating a function called setItem that will assign a key in an object to a specific value:
const setItem = <T, U extends keyof T>(obj: T) => (key: U, value): void => {
obj[key] = value
}
const person = {
name: 'James',
age: 13,
}
const setPerson = setItem(person)
setPerson('name', 125)
Despite setting the name property to a number, there are no compile time errors (due to the current type being 'any').
How can I instruct TypeScript to enforce the typeof value for obj[key]?