Im trying to split the code in this example: https://codesandbox.io/s/usecontroller-0o8px
but Im getting a type error when Im passing control={control} to input component.
(JSX attribute) control?: Control<FieldValues, object> | undefined
Type 'Control<formValues, object>' is not assignable to type 'Control<FieldValues, object>'.
The types of '_options.resolver' are incompatible between these types.
Type 'Resolver<formValues, object> | undefined' is not assignable to type 'Resolver<FieldValues, object> | undefined'.
Type 'Resolver<formValues, object>' is not assignable to type 'Resolver<FieldValues, object>'.ts(2322)
controller.d.ts(22, 5): The expected type comes from property 'control' which is declared here on type 'IntrinsicAttributes & { label?: string | undefined; supportive?: string | undefined; } & UseControllerProps<FieldValues, string> & InputHTMLAttributes<...> & { ...; }'
Here is my input component
type Props = {
label?: string
supportive?: string
} & UseControllerProps &
InputHTMLAttributes<HTMLInputElement>
const InputComp: FC<Props> = ({ label, supportive, ...props }) => {
...
const {
field,
fieldState: { invalid, isTouched, isDirty },
formState: { touchedFields, dirtyFields },
} = useController(props)
return <input {...field} />
}
when I pass formValues type to UseControllerProps<formValues> the error is gone.
I want to use the input component in different forms with different formValues How can I achieve that?
type Props<T> = {..} & UseControllerProps<T>function InputComp<T>(props: Props<T>) {}And then in the form, I pass the <FormType> type, like below:<Input<FormType> name='title' type='text' control={control} />