typescript - valoare: UnpackNestedValue<PathValue<T, Path<T>>>
Folosesc react-hook-form și primesc această eroare value: UnpackNestedValue<PathValue<T, Path<T>>> de fiecare dată când trec valoarea ca prop.
Iată componenta mea de buton comutator:
type Props<T> = {
height: number
} & UseControllerProps<T> &
InputHTMLAttributes<HTMLInputElement>
function SwitchButton<T>(props: Props<T>) {
const {
field: { onChange, value },
} = useController(props)
return (
<Switch height={props.height}>
<input type='checkbox' checked={value} onChange={onChange} />
<Slider height={props.height}></Slider>
</Switch>
)
}
În codul de mai sus primesc o eroare la atributul checked: Type 'UnpackNestedValue<PathValue<T, Path<T>>' nu poate fi atribuit tipului 'boolean | undefined'.
Acesta este formularul meu:
const defaultValues = {
title: '',
project: {
id: '',
title: ''
},
isOpen: false,
...
}
const { handleSubmit, control, setError, watch } =
useForm<FormType>({
defaultValues,
})
<form onSubmit={handleSubmit(onSubmitHandler)}>
<SwitchButton<FormType>
name='isOpen'
height={20}
control={control}
/>
...
</form>
import { NestedValue } from 'react-hook-form'
type FormType = {
title: string
project: NestedValue<{
id: string
title: string
}>
isOpen: boolean
...
}
Primesc aceeași eroare în toate celelalte componente de formular, știe cineva cum să rezolve asta? Mulțumesc