Closed mikeseese closed 4 months ago
Apparently this is desired behavior. I find it confusing the ObjectSchema.optional()
is not intended to allow the object to be undefined
but rather for it to be at least {}
. It seems like the design wants you to use object().default(undefined)
for this desired behavior. It's very counterintuitive, but it seems like that's the opinion the author wants, so I'll close this issue.
Describe the bug This bug is similar to #1890 where optional objects with required fields are causing unexpected behavior when the optional object isn't provided. However, this issue documents a problem with the latest version of
yup
and a different error.To Reproduce
It seems the CodeSandbox tests panel was removed, but here is a test that should pass, but the
objWithoutFoo
will fail.Expected behavior I expect all of the provided tests to pass. Required fields in an optional object should only be required if the optional object is defined.
Platform (please complete the following information):
Additional context N/A