Skip to content
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

feat(forms): Give form statuses a more specific type #42952

Closed
wants to merge 1 commit into from

Conversation

@dylhunn
Copy link
Contributor

@dylhunn dylhunn commented Jul 23, 2021

Make Form Statuses use stricter types.

Specifically: narrow the type used for form statuses from string to a union of possible statuses. Change the API methods from any to use the new type.

This is a breaking change. However, as discussed below, breakage seems minimal, and google3 has been prepped to land this.

Background: we uncovered these any typings in the course of design work for typed forms. They could be fixed in a non-breaking manner by piggybacking them on top of the new typed forms generics, but it would be much cleaner to fix them separately if possible.

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?

Currently, form status is described with just a plain string, and the return type of statusChanges is Observable<any>.

Issue Number: N/A

What is the new behavior?

Form status uses a more specific type, which can only be a valid status string (specifically, the union of all possible statuses). Accordingly, statusChanges and friends are strongly typed.

Does this PR introduce a breaking change?

  • Yes
  • No

Yes, this is a breaking change: some consumers will expect the status to be an arbitrary string, and after this change, it must be a valid status string. I ran a TGP in google3, and there were 20k broken tests, but I was able to fix them all by addressing only seven root causes by hand. Most root causes were type confusion regarding the any types we currently use in statusChanges (Googlers, see b/194913527). The very small number of root causes suggests external breakage will be minimal, and what breakage does occur is likely due to incorrect use of statusChanges. After discussion with Alex and Andrew K, we think that breakage should be minimal enough that no schematic is required.

Here is the breaking change blurb from the commit message:

A new type called FormControlStatus has been introduced, which is a union of all possible status strings for form controls. AbstractControl.status has been narrowed from string to FormControlStatus, and statusChanges has been narrowed from Observable<any> to Observable<FormControlStatus>. Most applications should consume the new types seamlessly. Any breakage caused by this change is likely due to one of the following two problems: (1) the app is comparing AbstractControl.status against a string which is not a valid status; or, (2) the app is using statusChanges events as if they were something other than strings.

Other information

TGP went green two days ago after making the fixes in google3.

@ngbot ngbot bot added this to the Backlog milestone Jul 23, 2021
@google-cla google-cla bot added the cla: yes label Jul 23, 2021
@dylhunn dylhunn force-pushed the dylhunn:narrow-status branch 2 times, most recently from 86efb37 to 6d2a8e4 Jul 23, 2021
@dylhunn
Copy link
Contributor Author

@dylhunn dylhunn commented Jul 29, 2021

@AndrewKushnir, can you do an initial review before I send this to a wider audience?

@dylhunn dylhunn force-pushed the dylhunn:narrow-status branch from 1f21d58 to 4ed1e6d Jul 29, 2021
@dylhunn dylhunn force-pushed the dylhunn:narrow-status branch from 4ed1e6d to 8b4599a Jul 29, 2021
@dylhunn dylhunn requested a review from AndrewKushnir Jul 29, 2021
@dylhunn dylhunn force-pushed the dylhunn:narrow-status branch from 8b4599a to 01950c8 Jul 29, 2021
@dylhunn dylhunn requested a review from alxhub Jul 29, 2021
@dylhunn dylhunn marked this pull request as ready for review Jul 29, 2021
@dylhunn dylhunn requested a review from JoostK Jul 29, 2021
@dylhunn dylhunn force-pushed the dylhunn:narrow-status branch 3 times, most recently from a91e5dc to 6552be8 Jul 29, 2021
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

LGTM 👍

@dylhunn dylhunn force-pushed the dylhunn:narrow-status branch 6 times, most recently from 5bf1af8 to 31e2632 Jul 29, 2021
Copy link
Member

@IgorMinar IgorMinar left a comment

LGTM for api change, let's please make sure that this change is properly documented in the change log and release notes. And let's keep an eye on the community feedback just in case the change causes unexpected pain.

Thank you!

Reviewed-for: public-api

@pullapprove pullapprove bot requested a review from jessicajaniuk Jul 30, 2021
Copy link
Contributor

@jessicajaniuk jessicajaniuk left a comment

LGTM 🍪

reviewed-for: public-api

@pullapprove pullapprove bot requested a review from petebacondarwin Jul 30, 2021
@alxhub
alxhub approved these changes Jul 30, 2021
@pullapprove pullapprove bot requested a review from alxhub Jul 30, 2021
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Reviewed-for: public-api

@dylhunn
Copy link
Contributor Author

@dylhunn dylhunn commented Aug 2, 2021

This is blocked until the final google3 fix is approved: cl/387384219

Copy link
Contributor

@dario-piotrowicz dario-piotrowicz left a comment

nice one 😍

Specifically: narrow the type used for form statuses from string to a union of possible statuses. Change the API methods from any to use the new type.

This is a breaking change. However, as discussed in the PR, breakage seems minimal, and google3 has been prepped to land this.

Background: we uncovered these any typings in the course of design work for typed forms. They could be fixed in a non-breaking manner by piggybacking them on top of the new typed forms generics, but it would be much cleaner to fix them separately if possible.

BREAKING CHANGE:

A new type called `FormControlStatus` has been introduced, which is a union of all possible status strings for form controls. `AbstractControl.status` has been narrowed from `string` to `FormControlStatus`, and `statusChanges` has been narrowed from `Observable<any>` to `Observable<FormControlStatus>`. Most applications should consume the new types seamlessly. Any breakage caused by this change is likely due to one of the following two problems: (1) the app is comparing `AbstractControl.status` against a string which is not a valid status; or, (2) the app is using `statusChanges` events as if they were something other than strings.
@dylhunn dylhunn force-pushed the dylhunn:narrow-status branch from 31e2632 to 9b5a552 Aug 3, 2021
@dylhunn
Copy link
Contributor Author

@dylhunn dylhunn commented Aug 4, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment