I have this type:
interface MyType {
name: string
age: number
friend: Person
}
and consider this state:
const [myState, setMyState] = useState<MyType>({.....})
and I have this function that changes a filed inside useState:
const handleChange = (filed: keyof MyType, value: unknown) => {
setMyState({
...myState,
[field]: value
})
}
how can I use generics or some other work around to type the value argument in the above function?
I expect my handleChange function to throw error when wrong value is passed to a field:
handleChange("name", 5);