fix(forms): include null in return types of .parent of abstract control - #32671
fix(forms): include null in return types of .parent of abstract control#32671lazarljubenovic wants to merge 1 commit into
Conversation
2195e1d to
944c759
Compare
944c759 to
27001a9
Compare
|
I can't find any info on changing golden files in developer documentation. Am I supposed to do it, or someone from the team? |
That's a good point. The contributor docs seem to be lacking in this area. I've opened up #33278 to track that. You need to run If you don't have Bazel installed globally in your CLI, I think that |
|
Hi @lazarljubenovic, thanks for creating this PR! 👍 The change looks good and as you mentioned it'd be a breaking change (so it can be included only into the major version) and I've added a label to indicate that. One of the next steps would be to estimate the amount of effort it would take to land this inside Google's codebase. Could you please rebase this PR and resolve conflicts, so I can run internal tests to see if any cleanup is needed? Please let me know if you need help with golden files update (you should see the command as the output of one of the failing CI jobs once you rebase). Thank you. |
e8a934b to
9602b54
Compare
|
Hi @lazarljubenovic, thanks for rebasing this PR and resolving conflicts! I've started internal google checks (and more broad internal checks) and will let you know what the next steps are once we estimate the amount of effort required to land the change. Couple comments/questions after reviewing the proposed change:
Thank you. |
|
@lazarljubenovic just a quick update: it turned out that this change is quite break-y in g3. I will try to estimate the effort on g3 side and will let you know what the next steps are. Thank you. |
jelbourn
left a comment
There was a problem hiding this comment.
LGTM
Reviewed-for: public-api
| private _parentMarkedDirty(onlySelf?: boolean): boolean { | ||
| const parentDirty = this._parent && this._parent.dirty; | ||
| return !onlySelf && parentDirty && !this._parent._anyControlsDirty(); | ||
| return !onlySelf && !!parentDirty && !this._parent!._anyControlsDirty(); |
There was a problem hiding this comment.
Now that parent can't be undefined, I think this goes more in line with recent developments:
const parentDirty = this._parent !== null && this._parent.dirty;
return !onlySelf && parentDirty && !this._parent!._anyControlsDirty();TS might even be smart enough for you to not need the ! on this._parent, but not sure
There was a problem hiding this comment.
TS is not smart enough without an explicit guard function: playground.
But you could drop the const parentDirty statement since it is a bit superfluous now:
return !onlySelf && this._parent !== null && this._parent.dirty && !this._parent._anyControlsDirty();There was a problem hiding this comment.
We are very close to landing this PR (that required some cleanup in Google's codebase), so I think it'd be great to change this code in a followup refactoring PR (i.e. keep the current code as is for now so we don't need to re-run all tests again).
As of angular#32671, the type of `AbstractControl.parent` can be null which can cause compilation errors in existing apps. These changes add a migration that will append non-null assertions to existing unsafe accesses. ```` // Before console.log(control.parent.value); // After console.log(control.parent!.value); ``` The migration also tries its best to avoid cases where the non-null assertions aren't necessary (e.g. if the `parent` was null checked already).
This PR is created for testing purposes only to check angular/angular#32671 PR with listed applications.
|
Quick update: I ran tests in the |
|
Note to Caretaker: this PR is ready to go, all tests are passing (including a global TAP) and all approvals are granted. The CI indicates 4 pending reviews, but I'm unable to remove them (looks like a glitch in GitHub UI). |
As of #32671, the type of `AbstractControl.parent` can be null which can cause compilation errors in existing apps. These changes add a migration that will append non-null assertions to existing unsafe accesses. ```` // Before console.log(control.parent.value); // After console.log(control.parent!.value); ``` The migration also tries its best to avoid cases where the non-null assertions aren't necessary (e.g. if the `parent` was null checked already). PR Close #39009
|
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. |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
AbstractControl#parentreturns a defined value.Issue Number: #16999
What is the new behavior?
AbstractControl#parentcan returnundefined.Does this PR introduce a breaking change?
Technically yes since we're changing the public API but then again, we're fixing a lie we told users before.
Other information