I'm working on a React project using TypeScript and react-hook-form. In some place I use the given function register() that have to be used like that (according to the official documentation):
<input
name="test"
ref={
register({
required: true
})
}
/>
The problem I'm facing here is that this function is typed in such a way that it return void
:
(Ref, validateRule?) => void
But the attribute ref
of the native input
tag has to be of type:
string | ((instance: HTMLInputElement | null) => void) | RefObject<HTMLInputElement> | null | undefined
So naturally TypeScript throws me this error:
Type 'void' is not assignable to type 'string | ((instance: HTMLInputElement | null) => void) | RefObject | null | undefined'
Do you have an idea of how I can use this library while respecting the types? Is this a mistake on the part of the library itself?