feat(forms): add strict reactive forms api#38906
feat(forms): add strict reactive forms api#38906MBuchalik wants to merge 1 commit intoangular:masterfrom
Conversation
Add StrictFormArray, StrictFormControl and StrictFormGroup, allowing the developer to specify a "form model". This makes the structure of forms strictly typed, which prevents errors and leads to better support for code auto completion.
|
@MBuchalik thanks for creating this PR. Improving types in Angular forms is on our Roadmap. We are looking into possible ways on how we can update existing classes to improve typings (see #38406). If we come across major blockers (and/or unclear upgrade path) during the research, we may need to reconsider the approach. Let's keep this PR open, we'll get back to it once the research in #38406 is completed (no ETA at this moment). Thank you. |
|
Sounds good 👍 |
|
1 month has passed since last commit in #38406. Any news? Need any help? |
|
Thank you for this PR, and I have read it in detail over the last ~2 months while working on Typed Forms. This was quite valuable in the design phase, but we ultimately decided to add types to the existing API later rather than wrapping it with a new layer. I am closing this PR in favor of the in-progress #43834. You can find in-depth justification of decision to extend rather than wrap on that PR's design doc. I'll be sure to acknowledge your contribution with special thanks in the changelog when the above PR lands. |
|
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. |
Add StrictFormArray, StrictFormControl and StrictFormGroup, allowing the developer to specify a "form model".
This makes the structure of forms strictly typed,
which prevents errors and leads to better support for code auto completion.
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?
Reactive Forms are currently not strongly typed. This leads to a suboptimal developer experience and does not catch common mistakes (e.g. typos).
Issue Number: #13721
What is the new behavior?
There are (/have been) multiple attempts to make FormArray, FormControl and FormGroup type safe. My proposal is different compared to the already existing ones: Instead of directly making these three classes type safe, I have introduced three new classes: StrictFormArray, StrictFormControl and StrictFormGroup (inheriting from their non-strict variants).
Developers have to define a separate "form model" that describes the structure of the form. Once this has been done, you get lots of benefits, including support for code suggestions/autocompletion, warnings when accessing non-existing controls, etc.
Benefits compared to other approaches:
Drawbacks:
Does this PR introduce a breaking change?
Other information
I was running the tests on a pretty slow computer, so many just timed out (
FirefoxHeadless failed 2 times (timeout). Giving up.) Hoping for CI to provide the results.Since my PR basically only includes a new model, I did not know if I had to create new tests. If so, I would be happy about a small explanation/example on how these tests should look like. My thoughts: I am literally only forwarding calls to the super classes, so there isn't much that could break.
(And one small thing: Most of the examples from the docs are based on ones of the respective non-strict version.)