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

Fix error where property 'value' does not exist on type 'ValidationError’ #794

Merged

Conversation

francjohny
Copy link
Contributor

@francjohny francjohny commented Nov 6, 2019

What went wrong?

Accessing property in union of object types fails for properties not defined on all union members.

error TS2339: Property 'value' does not exist on type 'ValidationError'.
  Property 'value' does not exist on type '{ location?: undefined; param: "_error"; msg: any; nestedErrors: ValidationError[]; }'.

Proposed Fix

Add optional types to all validation error fields for each union member. Fixes #795.

Related Issue

microsoft/TypeScript#12815

Environment

TypeScript v3.7.2

@coveralls
Copy link

coveralls commented Nov 6, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling 8f30202 on francjohny:fix-validation-error-types into 637c88a on express-validator:master.

This fixes the error when accessing property 'value' in union object type 'ValidationError’ for properties not defined on all union members.
@francjohny
Copy link
Contributor Author

@gustavohenke could you please review this PR when you are free? Thanks!

Copy link
Member

@gustavohenke gustavohenke left a comment

Choose a reason for hiding this comment

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

I made a slight change for type safety. How does it look?

@francjohny
Copy link
Contributor Author

Looks good to me, thanks for the improvement for type safety. @gustavohenke

@gustavohenke gustavohenke merged commit d5fc631 into express-validator:master Nov 24, 2019
@gustavohenke
Copy link
Member

Shipped in v6.3.0!

@lock
Copy link

lock bot commented Jan 24, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error TS2339: Property 'value' does not exist on type 'ValidationError’
3 participants