I'm trying to get typescript working with fields that can belong to different forms. I'd like the Field to define the fields that are needed in the form, so that it can be reused. I've currently used Control<any> to circumvent the issues, but that limits typescript utility. The error that I'm getting is
The types of '_options.resolver' are incompatible between these types.
Type 'Resolver<IFormAncestor, any> | undefined' is not assignable to type 'Resolver<DepForm, any> | undefined'.
Type 'Resolver<IFormAncestor, any>' is not assignable to type 'Resolver<DepForm, any>'.
44 <TestField control={control} trigger={trigger} getValues={getValues} />
Type 'DepForm' is not assignable to type 'IFormAncestor'.
44 <TestField control={control} trigger={trigger} getValues={getValues} />
interface IFormAncestor {
a: string;
b: string;
c: string;
}
interface DepForm {
a: string;
b: string;
}
export const TestField = (props: {
control: Control<DepForm>;
getValues: UseFormGetValues<DepForm>;
trigger: UseFormTrigger<DepForm>;
}) => {
props.getValues();
props.trigger();
return (
<Controller
name="a"
control={props.control}
defaultValue={''}
render={({ field }) => {
return (
<div>{field.value}</div>
);
}}
/>
);
};
function TestingAncestorForm() {
const { control, trigger, getValues } = useForm<IFormAncestor>({
mode: 'onBlur',
});
return (
<div>
<TestField control={control} trigger={trigger} getValues={getValues}/>
</div>
);
}
Is there a way to get this working? Cheers!