I am trying to work out how to create a generic object property updater which is properly typed in TypeScript
const [originalObj, setOriginalObj] = useState<MyModel>(defaultModel)
const updateModelProp = <T extends keyof MyModel> (key: T, value: any) => {
const newModel = { ...originalObj, [key]: value }
setOriginalObj(newModel)
}
I have it working, other than the 'value' column, where I want it to use TypeScript to ensure you are using the correct type to the model provided.
Can anyone help?