string().required().optional() thinks empty string is invalid. Because undefined is valid in this case, treating empty string as invalid is strange.
I understand that string().defined().optional() and string().required().notRequired() are the correct usages. But I think it is still nice to make string().required().optional() to work properly.
Also, .partial() and .deepPartial() always call .optional() so object({ str: yup.string().required() }).partial() could also be an issue.
Describe the bug
Depends on the definition, it may not be a Bug.
string().required().optional()
thinks empty string is invalid. Becauseundefined
is valid in this case, treating empty string as invalid is strange.I understand that
string().defined().optional()
andstring().required().notRequired()
are the correct usages. But I think it is still nice to makestring().required().optional()
to work properly.Also,
.partial()
and.deepPartial()
always call.optional()
soobject({ str: yup.string().required() }).partial()
could also be an issue.To Reproduce
https://stackblitz.com/edit/vitejs-vite-pwmcyx?file=main.js
Expected behavior
yup.string().required().optional().validate('')
should be valid.Platform (please complete the following information):