How to avoid type error on validationSchema when using yup with useForm<T>? #3824
-
Hi, I am new to vee-validate and I was wondering how we can use yup with a typed form like in this sample : public interface MyForm {
myField1: string,
myField2: string
}
const { handleSubmit } = useForm<MyForm>({
validationSchema: object({
myField1: string().required(),
myField2: string().min(3),
}),
}); I have an error on validationSchema property : "type OptionalObjectSchema ..... is not assignable to type". |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
This has been a problem for a while because it seems like Yup 1.0 might resolve this but I haven't checked their progress yet or the type of changes they will introduce. Either way vee-validate shouldn't depend on |
Beta Was this translation helpful? Give feedback.
This has been a problem for a while because it seems like
required
doesn't make the type non-nullable. In 4.6 this will be fixed since we drop inferring the types from yup schema. Sadly we will use some autocompletion and type features but most people cast it toany
to avoid the errors they keep getting.Yup 1.0 might resolve this but I haven't checked their progress yet or the type of changes they will introduce. Either way vee-validate shouldn't depend on
yup
types because it forces people to install it into their projects to avoid typescript issues.