-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
feature(forms): Improve typings for (Async)Validators #48679
feature(forms): Improve typings for (Async)Validators #48679
Conversation
79a2100
to
37c6732
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reviewed-for: public-api
37c6732
to
ee390e8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reviewed-for: public-api
ee390e8
to
dd4e413
Compare
I just solved the conflicts, is anything preventing the PR from moving forward ? |
With this commit, AsyncValidatorFn cannot be passed as ValidatorFn anymore in FormControl. fixes: angular#48676
dd4e413
to
da189de
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reviewed-for: public-api
This PR was merged into the repository by commit 07a1aa3. |
Previous PR angular#48679 introduced an extraordinarily subtle issue with FormBuilder type inference. FormBuilder is way too polymorphic, and I'm looking forward to improving/replacing it with something that has fewer argument shapes. In particular, this typing issue applied only when the following are all true: 1. There is a FormBuilder shorthand call 2. It uses the `ControlConfig` shorthand notation (e.g. `[value, validator]`) 3. The value itself is an array, which goes into a `FormControl` 4. The validator is not static, e.g. it's not `Validators.required`, but something that returns a dynamic `ValidatorFn` In particular, angular#4 was the reason the breakage slipped through my very exhaustive tests. This fix adds the recently-narrowed `ValidatorFn` back into the list of types that are systematically excluded from the inferred value type of the form control. C’est la vie, and hoping to simplify FormBuilder someday.
Independent of the bug fixed in #49693, this caused legitimate breakage in g3 (passing AsyncValidatorFn where ValidatorFn is expected), which needs to be cleaned up. We'll have to reopen this and try again. |
… validator. Previously, this PR cleaned up a bug introduced by angular#48679. However, since that PR needed to be rolled back, this PR now just checks in the test, to prevent that issue from re-occurring in the future.
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
With this commit,
AsyncValidatorFn
cannot be passed asValidatorFn
anymore inFormControl
.To exclude Promises, excluding object with
then
(see thenables), to exclude Observables I chose to exclude object with the keysubscribe
.fixes: #48676
PR Type
What kind of change does this PR introduce?
Does this PR introduce a breaking change?
The only breaking change should be misuse reports by the compiler of
AsyncValidatorFn
asValidatorsFn
inFormControl
constructors.