const obj = {
role : 'admin',
user : {
id : 1,
name : 'vasa',
},
}
const fun = <T>(obj: T):
Record<`set${Capitalize<string & keyof T>}`, (a : T[keyof T]) => void>
=> {
const action = {}
for(const key in obj){
action[key] = (value) => {console.log(value)}
}
return action
}
const action = fun(obj)
// issue
action.setRole({id: 2, name: 'bug'})
setRole is receiving the wrong type as T[keyof T] combines all types into one type when it's supposed to be:
setRole(string)
setUser(object)