I have a TypeScript error in handleSubmit function.
- I'm retrieving
handleSubmitfunction viauseForm:
const {handleSubmit, control, watch, reset} = useForm() - I'm defining submit function:
const submit = (data: { file: File, crop: Area }) => { onSubmit(data.file, data.crop) // onSubmit is passed from parent component } - I pass
handleSubmitinonSubmitprop ofFormcomponent
<Form onSubmit={handleSubmit(submit)}> // registering form fields here </Form> - Got the following TypeScript error:
Argument of type '(data: { file: File; crop: Area;}) => void' is not assignable to parameter of type 'SubmitHandler<FieldValues>'. [1] Types of parameters 'data' and 'data' are incompatible. [1] Type '{ [x: string]: any; }' is missing the following properties from type '{ file: File; crop: Area; }': file, crop TS2345 If I pass handleSubmit like this everything works fine.
<Form onSubmit={handleSubmit(submit as any)}></Form> But I'm trying not to use any in my project. So if anyone could explain how should i type parameter for handleSubmit function I will appreciate it ;)