I'm geting type's problems when I try to use SubmitHandler type to typping onSubmit prop, I'm getting:
TS2345: Argument of type 'SubmitHandler<T>' is not assignable to parameter of type 'SubmitHandler<FieldValues>'. Type 'FieldValues' is not assignable to type 'T'. 'T' could be instantiated with an arbitrary type which could be unrelated to 'FieldValues'.
Implementation
import { FieldValues, useFormContext, SubmitHandler } from 'react-hook-form';import { Pressable, Text } from 'react-native';type ButtonProps<T extends FieldValues> = PressableProps & { onSubmit: SubmitHandler<T>;};function SubmitButton<T = FieldValues>({ onSubmit, ...RestButtonProps }: ButtonProps<T>) { const { handleSubmit } = useFormContext(); return (<Pressable {...RestButtonProps} onPress={() => handleSubmit(onSubmit)}><Text>Submit</Text></Pressable> );}type LoginFormValues = { email: string; password: string;};function LoginForm() { const handleSubmit: SubmitHandler<LoginFormValues> = ({ email, password }) => console.warn(email, password); return (<SubmitButton<LoginFormValues> title="Sign In" onSubmit={handleSubmit} /> );}