feat: return an array of errors from a single validator (custom & schema library)#1090
Closed
Balastrong wants to merge 14 commits intoTanStack:mainfrom
Closed
feat: return an array of errors from a single validator (custom & schema library)#1090Balastrong wants to merge 14 commits intoTanStack:mainfrom
Balastrong wants to merge 14 commits intoTanStack:mainfrom
Conversation
Allow string and string[] as returned value from validator but always set string[] on error maps
|
View your CI Pipeline Execution ↗ for commit 86c9943.
☁️ Nx Cloud last updated this comment at |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1090 +/- ##
==========================================
+ Coverage 86.60% 88.43% +1.83%
==========================================
Files 29 29
Lines 1172 1159 -13
Branches 287 281 -6
==========================================
+ Hits 1015 1025 +10
+ Misses 144 124 -20
+ Partials 13 10 -3 ☔ View full report in Codecov by Sentry. |
Member
|
Closing this in favor of #1104, which offers more flexibility over how types are handled. This PR led to the idea I had for that PR tho! @Balastrong continues to be a legend! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses the frequent request of being able to return multiple errors from a single validator.
Validator functions (aka what you put inside
validators: { onChange: () => ... }) can now return aValidationResultthat isundefined | false | null | ValidationError | ValidationError[]withValidationErrorbeing astring.Existing validators returning a single string will keep working, additionally you can now also return an array of strings.
As a side effect, validators defined with schema libraries will no longer be cut to the first error by default, but all errors will be shown instead.
Breaking Changes
Being able to return an array of strings from a validator means
errorMap.onChange& co will no longer be a string but an array.Documentation has been updated showing the quickest change to keep the previous behaviour:
In case you were using
meta.errorsto display all your errors there won't be any breaking change since this value will always be a (flat) aggregate array of errors.Feedback is welcome!