Code like this I want to set the object value with key, the key param of function setObjKeyValue is one of the key of obj, and the type of the value param is correspondingly the value of the key. But I have no idea how to define the value type. I think Generic probably sovely my problem, could anyone give me some tips?
interface Obj {
foo: number,
bar: string
}
const obj: Obj = {
foo: 2333,
bar: 'fff'
}
function setObjKeyValue(key: keyof Obj, value):Obj {
obj[key] = value
return obj
}