Skip to content
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

types(validation): support function for validator message property, and add support for accessing validator reason #14499

Merged
merged 1 commit into from Apr 7, 2024

Conversation

vkarpov15
Copy link
Collaborator

Fix #14496

Summary

The SchemaType.prototyp.validate API docs include an example of returning the original error message that the validator threw instead of Mongoose's automatic message formatting:

schema.path('name').validate({
  validator: function() { throw new Error('Oops!'); },
  // `errors['name']` will be "Oops!"
  message: function(props) { return props.reason.message; }
});

The TypeScript types disallow this currently.

Examples

… and add support for accessing validator `reason`

Fix #14496
@hasezoey hasezoey added the typescript Types or Types-test related issue / Pull Request label Apr 6, 2024
@vkarpov15 vkarpov15 added this to the 8.3.1 milestone Apr 7, 2024
@vkarpov15 vkarpov15 merged commit d475ce8 into master Apr 7, 2024
5 checks passed
@vkarpov15 vkarpov15 deleted the vkarpov15/gh-14496 branch April 7, 2024 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typescript Types or Types-test related issue / Pull Request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing reason in the ValidatorProps type
2 participants