Skip to content

refactor(forms): Fix weak helper types in the Forms package - #44370

Closed
dylhunn wants to merge 1 commit into
angular:masterfrom
dylhunn:typed-cleanups
Closed

dylhunn wants to merge 1 commit into
angular:masterfrom
dylhunn:typed-cleanups

Conversation

@dylhunn

@dylhunn dylhunn commented Dec 3, 2021 •

Copy link
Copy Markdown
Contributor

Fix weak helper types in the Forms package, mostly Function types that can be strengthened to specific callbacks. This was originally proposed as part of Typed Forms, but it should be possible to submit at least some of these changes separately and unconditionally (i.e. without relying on TypedOrUntyped.)

It is desirable to land this separately to reduce the scope of the Typed Forms PR, by focusing it only on the new type parameters (rather than incidental strictness fixes).

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Many forms methods have unnecessarily weak types (e.g. Function).

Issue Number: #13721

What is the new behavior?

The types of these methods are strengthened to specific callbacks.

Does this PR introduce a breaking change?

No

Other information

@google-cla google-cla Bot added the cla: yes label Dec 3, 2021
@dylhunn

dylhunn commented Dec 3, 2021 •

Copy link
Copy Markdown
Contributor Author

Presubmit for this change is green.

@dylhunn dylhunn added action: review The PR is still awaiting reviews from at least one requested reviewer area: forms cross-cutting: types labels Dec 3, 2021
@ngbot ngbot Bot modified the milestone: Backlog Dec 3, 2021
@dylhunn dylhunn added the target: minor This PR is targeted for the next minor release label Dec 3, 2021
@dylhunn
dylhunn marked this pull request as ready for review December 3, 2021 19:47

@jessicajaniuk jessicajaniuk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🍪

reviewed-for: public-api

@AndrewKushnir AndrewKushnir left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dylhunn thanks for improving types! 👍
The change looks great, just left a couple comments/suggestions.

Comment thread packages/forms/src/directives/shared.ts Resolved
Comment thread packages/forms/src/model.ts Resolved
Comment thread packages/forms/src/model.ts Resolved

@AndrewKushnir AndrewKushnir left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @dylhunn 👍

Comment thread packages/forms/src/model.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we could also specify the return type?

Suggested change
_reduceChildren<T>(initValue: T, fn: (acc: T, control: AbstractControl, name: string) => T) {
_reduceChildren<T>(initValue: T, fn: (acc: T, control: AbstractControl, name: string) => T): T {

Comment thread packages/forms/src/model.ts Resolved
@pullapprove
pullapprove Bot requested a review from AndrewKushnir December 7, 2021 19:08

@AndrewKushnir AndrewKushnir left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-for: public-api

@dylhunn dylhunn added target: major This PR is targeted for the next major release and removed target: minor This PR is targeted for the next minor release labels Dec 8, 2021
@dylhunn
dylhunn removed the request for review from jelbourn December 8, 2021 17:26
@pullapprove
pullapprove Bot requested a review from jelbourn December 8, 2021 17:27
@dylhunn
dylhunn removed request for alxhub and jelbourn December 8, 2021 17:31
@dylhunn dylhunn added target: patch This PR is targeted for the next patch release and removed action: review The PR is still awaiting reviews from at least one requested reviewer target: major This PR is targeted for the next major release labels Dec 8, 2021
@dylhunn dylhunn changed the title feat(forms): Fix weak helper types in the Forms package refactor(forms): Fix weak helper types in the Forms package Dec 8, 2021
@dylhunn

dylhunn commented Dec 8, 2021 •

Copy link
Copy Markdown
Contributor Author

@alxhub I'm actually just going to drop the public API change from this PR -- I think it's still worth fixing the @internal methods to clean things up, and we can do the public method in the next major.

@dylhunn dylhunn added action: merge The PR is ready for merge by the caretaker and removed action: merge The PR is ready for merge by the caretaker labels Dec 8, 2021
@dylhunn dylhunn added the action: merge The PR is ready for merge by the caretaker label Dec 8, 2021
@alxhub

alxhub commented Dec 10, 2021

Copy link
Copy Markdown
Member

FYI, this refuses to merge because the commit type is feat, but the PR is target: patch. We should change the commit to a refactor.

…Function` types that can be strengthened to specific callbacks. This was originally proposed as part of Typed Forms, but it may be possible to submit at least some of these changes separately and unconditionally (i.e. without relying on `TypedOrUntyped`.)

It is desirable to land this separately to reduce the scope of the Typed Forms PR, by focusing it only on the new type parameters (rather than incidental strictness fixes).
@dylhunn

dylhunn commented Dec 10, 2021

Copy link
Copy Markdown
Contributor Author

@alxhub Fixed.

@alxhub

alxhub commented Dec 10, 2021

Copy link
Copy Markdown
Member

This PR was merged into the repository by commit 7df9127.

alxhub pushed a commit that referenced this pull request Dec 10, 2021
…Function` types that can be strengthened to specific callbacks. This was originally proposed as part of Typed Forms, but it may be possible to submit at least some of these changes separately and unconditionally (i.e. without relying on `TypedOrUntyped`.) (#44370)

It is desirable to land this separately to reduce the scope of the Typed Forms PR, by focusing it only on the new type parameters (rather than incidental strictness fixes).

PR Close #44370
@alxhub alxhub closed this in 7df9127 Dec 10, 2021
@dylhunn
dylhunn deleted the typed-cleanups branch December 14, 2021 23:06
dylhunn added a commit to dylhunn/angular that referenced this pull request Dec 15, 2021
I previously strengthened some weak types in angular#44370. One of these fixes exposed an incorrect call into `_reduceChildren` from `_reduceValue`. This was caught in google3 by a caller who was extending `FormGroup` and overriding these methods.

Special thanks to Bart G for catching this issue and suggesting a fix.
alxhub pushed a commit that referenced this pull request Dec 15, 2021
)

I previously strengthened some weak types in #44370. One of these fixes exposed an incorrect call into `_reduceChildren` from `_reduceValue`. This was caught in google3 by a caller who was extending `FormGroup` and overriding these methods.

Special thanks to Bart G for catching this issue and suggesting a fix.

PR Close #44483
alxhub pushed a commit that referenced this pull request Dec 15, 2021
)

I previously strengthened some weak types in #44370. One of these fixes exposed an incorrect call into `_reduceChildren` from `_reduceValue`. This was caught in google3 by a caller who was extending `FormGroup` and overriding these methods.

Special thanks to Bart G for catching this issue and suggesting a fix.

PR Close #44483
@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Jan 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: forms cla: yes cross-cutting: types target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants