-
Notifications
You must be signed in to change notification settings - Fork 934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Difference between let schema = yup.object().shape({}) and let schema = yup.object({}) #1222
Comments
there is no difference, the latter is a shortcut for the first one |
Then why have the long version? |
With the long version yup.object().shape() I get some errors when extracting and dealing with the type extracted by yup.InferType, I don't understand why with the short version those errors disappeared |
I've found that the |
There is different because InferType complains with |
The actual answer is that |
Another purpose of using .shape({Field1: yup....., Field2: yup.....}, [[Field1, Field2], [Field3, Field4]]) is to validate fields conditionally. For e.g. When the Field1 === "Use Custom Option" then Field2 is required. Another e.g. can be Field3 === 5 then Field4 is required and Field4 === 7 then Field3 is required. This dependency of fields can be grouped inside of second parameter of shape which is an array, like in above case Field1 & Field2 are dependent and Field3 & Field4 are dependent. |
What is the difference between
let schema = yup.object().shape({})
andlet schema = yup.object({})
I can do either when setting up schema for React / Formik and both seems to work the same way.
The text was updated successfully, but these errors were encountered: