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

Narrow down ExpressJoiError type to assume the Joi.ValidationResult is an error #46

Merged

Conversation

feclist
Copy link
Contributor

@feclist feclist commented Nov 29, 2024

👋

While writing some error handling middleware using ExpressJoiError I noticed that the type also includes the non-error type of the Joi.ValidationResult:

{
    error: undefined;
    warning?: ValidationError;
    value: TSchema;
}

I assume (and correct me if I'm wrong!) that the ExpressJoiError is only raised when the Joi.ValidationResult contains the error field. If that is true then Extracting the error variant of the type will result in a more narrow type to use.

Additionally I've also added the TSchema generic type on the ExpressJoiError that's passed into the Joi.ValidationResult to allow for more accurate handling when it comes to the schema that raised the error.

Copy link
Owner

@evanshortiss evanshortiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great PR. Can you update to the suggested version number and I can do a release.

package.json Outdated
@@ -1,6 +1,6 @@
{
"name": "express-joi-validation",
"version": "5.0.1",
"version": "5.0.2",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"version": "5.0.2",
"version": "5.1.0",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

@evanshortiss evanshortiss merged commit 023a7f7 into evanshortiss:master Dec 11, 2024
1 check passed
@evanshortiss
Copy link
Owner

Published as v6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants