fix: only allow setting manual errors according to the defined validators#1482
Conversation
|
View your CI Pipeline Execution ↗ for commit 9810565.
☁️ Nx Cloud last updated this comment at |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1482 +/- ##
==========================================
- Coverage 88.98% 88.96% -0.02%
==========================================
Files 31 31
Lines 1398 1396 -2
Branches 353 353
==========================================
- Hits 1244 1242 -2
Misses 137 137
Partials 17 17 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
How should server errors be set now? form.setErrorMap({ onServer: 'login or password is incorrect' });
// onServer: Type 'string' is not assignable to type 'undefined'. |
|
You shouldn't need to manually set server errors as they're automatically set from your server validator or in general by returning something from any other validator. This also gives lets |
|
How would I set an error that comes from a react-query mutation that was fired off on submit and failed? Previously this was no problem. |
|
The problem is also that since you have no validators set, when you read that error you have The only difference now is that For now you can |
|
Also please @MGRatEJOT can you share your scenario in a separate issue? I'd like to have a better look. It would be great if you can include a stackblitz link |
|
Thanks for the quick info. What is the best practice for my use case? The example with React Query lacks a validator and error handling. My setup is similar, but my query might return an error that I need to display on the form. Edit: Sorry, I was already replying when your second post came in. |
|
I apologize upfront if this question is just wasting everybody's time. But could someone confirm, whether return field errors from |
|
I don't think I'm understanding the question, onSubmitAsync follows the same rules of the other validators and types are fully inferred. |
|
@Balastrong Apologies, here is proper issue: #1537. Thanks! |
At the current state the types of
form.setErrorMapare wrong (asking for a validator function) andfield.setErrorMapallows everything.With this PR the allowed types are now exactly the ones coming from the defined validators to ensure type safety is correct when reading the values (e.g. from
field.getMeta().errors)