setErros and validate return type missmatch
Hi @joanpablo
setErrors accepts non nullable value https://github.com/joanpablo/reactive_forms/blob/master/lib/src/models/models.dart#L545
but the built on validators return nullable value https://github.com/joanpablo/reactive_forms/blob/master/lib/src/validators/email_validator.dart#L13
Hi @vasilich6107,
Mmm yes, you are right, In my opinion, you should not use the method setError to set a null value. If the idea is to clear all errors then you can just pass an empty object setError({}) or maybe we should have a removeAllErrors public method.
Hi @joanpablo The main issue is that I cannot use
someField.setErrors(EmailValidator.validate(someField));
I have to write
someField.setErrors(EmailValidator.validate(someField) ?? {});
Why not to make those types identical?
This is one of the things that could be improvedwith stricter typing and getting rid of dynamic.
@kuhnroyal im 100% with you Dynamic is pain
Mmm, I see @vasilich6107,
But, what does this supposed to do?
someField.setErrors(null);
1-) Remove all errors from the field? 2-) Don't do anything at all?
And at the end:
someField.setErrors(EmailValidator.validate(someField) ?? {});
I don't think it looks too bad.
I can understand that I need to pass the results from EmailValidator.validate(someField) or empty object in case of null, it is clear to me. but this expression: someField.setErrors(null); is not clear to me.
Also AbstractControl.errors is not nullable, I mean you will always get an instance of a Map, not a null value, that's why the setError does not allows setting a null value. If you change setErrors to accept a null then you will need to change the data type of AbstractControl.errors, and I don't think it really gives an advantage.
@joanpablo i will write my thoughts a little bit later. While you are here could you comment on this https://github.com/joanpablo/reactive_forms/issues/200#issuecomment-894694053