The Most Popular Feature Request in Angular History
Angular, the go-to framework for enterprise apps, has been widely praised for its forms packages, particularly reactive forms. However, one major issue has plagued developers for years: the lack of strong typing in reactive forms. This limitation has led to potential issues and maintenance headaches, making it challenging to build complex forms.
The Community’s Plea
The Angular community has been vocal about this issue, with numerous feature requests, including the infamous issue #13721. This concise and straightforward request has garnered massive support, with many developers eager for a solution. The request is simple: create strongly typed form controls to ensure type safety and maintainability.
A Long-Awaited Solution
After five years of waiting, the Angular team has finally reached the RFC stage with a prototype demo. This milestone marks a significant step forward in addressing the community’s concerns. But why did it take so long? The journey to this point has been marked by numerous discussions, pull requests, and third-party libraries, all attempting to fill the void left by the lack of strong typing.
The RFC and Prototype
The RFC, titled “Strictly Typed Reactive Forms,” proposes a solution that adds generics to AbstractControl classes and FormBuilder, making forms type-safe and null-safe for both controls and values. The prototype demonstrates the power of strong typing, with features like the Get
method, which uses TypeScript’s template string literal and recursive type to perform type inference.
Technical Highlights
The prototype’s control-types approach ensures that the type parameter on FormGroup is an object containing controls. This design provides users with the option to avoid unnecessary nullable types, while keeping existing code working. The reset
method has also been reworked to set the value of control to its default value instead of null, preventing undesired behavior.
The Future of Typed Reactive Forms
With the RFC closed, the Angular team is poised to release the feature in Angular v14, complete with a migration schematic. While there are still limitations to address, such as template type checking for validators and ControlValueAccessor, the community’s persistence and hard work have brought this critical feature to the forefront.
What This Means for Developers
The arrival of strongly typed reactive forms will elevate Angular to new heights, making it an even more attractive choice for complex form-based applications. As the Angular team continues to refine and improve this feature, developers can look forward to a more robust and maintainable framework.
Experience Your Angular Apps Like Never Before
Debugging Angular applications can be challenging, but with LogRocket, you can monitor and track Angular state and actions for all users in production. Try LogRocket today and start modernizing your debugging process!