-
-
Notifications
You must be signed in to change notification settings - Fork 22
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
feat: implement requiredIf rules #42
Conversation
maybe it's my English that's lacking here, so tell me if i am wrong otherwise, looks perfect. cool and simpler alternative to unions 👌 |
Yeah, your variation seems more natural to speak. Let's see if @RomainLanz thinks the same and then I can update the method names. |
I agree with @Julien-R44, |
* the validation options, we can safely copy them by reference. | ||
*/ | ||
protected cloneValidations(): Validation<any>[] { | ||
return this.validations.map((validation) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would be better to directly use structuredClone()
?
return structuredClone(this.validations)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh did not know about that. Will do in a separate PR
The
requiredIf
rules offer an alternate API to thevine.union
which is less type-safe but also simpler to write and express conditions.Here's a quick example between the
vine.union
and therequiredIf
rules.With
vine.union
The output type will be a union as well.
With
requiredIfMissing
The output will have both
email
andphone
as optional even though one of them will be defined at runtime.The
requiredIfMissing
rules are helpful when you do not care much about the output data-types and you do not want to narrow them. For example, validate data and store it as a JSON blob in the database