-
Notifications
You must be signed in to change notification settings - Fork 6
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
Checking the Result #30
Comments
I ended up using the above described solution and have another suggestion: |
I would also really prefer to have an Here's a subclass I typed up quick to refactor the export class MyValidator<T> extends Validator<T> {
constructor() {
super();
}
validate = (value: T) => {
const result = super.validate(value);
return {
isValid: Object.keys(result).length === 0,
...result,
};
};
} |
Hi @leherv - thanks for your feedback 😃
This is due to the way the library was initially designed to plug and play as seamlessly as possible with Formik, which expects an object with keyed validation errors. I will consider how I can make it easier to check for validity, but for now the wrapper class proposed by @celluj34 above looks great (thanks!).
I'm not sure I understand fully what you mean here - would you be able to provide some code samples to show the behaviour you're mentioning? If a property on your type is required (not optional) yet is missing in values at runtime then I would say your type should make that property optional, and you will need to validate it explicitly with a
This is a fair point - I will consider adding a |
Hi, really like the library. I was looking at class-validator and immediately hit the problem of not being able to validate properties together or set a validator for a nested object. I also have my roots in C# so I found your library via fluentvalidation.
The only problem I am having right now is that it is not very convenient to check if the result is actually failed validation or a successful one. Is this intentional?
I would expect to be able to call .isValid() on the result of the validation. How would you recommend checking for success?
Checking if there are no keys on the result via Object.keys(result).length === 0?
The text was updated successfully, but these errors were encountered: