Closed StephenSPaul closed 1 month ago
Hi, basically this is the same request as #47834, let's continue tracking this over there.
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.
Which @angular/* package(s) are relevant/related to the feature request?
forms
Description
I absolutely love Angular forms, and now with typed forms, it is arguably one of Angular's strongest USPs, so THANK YOU!
At the moment,
FormGroup.value
returns aPartial<T>
because any of the controls may be disabled, and therefore may beundefined
. This has already been noted with https://github.com/angular/angular/issues/46341.FormControl.value
should also therefore returnT | undefined
but I digress...I would like an option to instantiate a
FormControl
/FormGroup
that restricts whether it (or any of its children) can subsequently be enabled/disabled or not. This will have the benefit of creating more accurate typings forformGroup.value
where only 'disableable' controls can have a possibleundefined
value.Proposed solution
The
enable()
/disable()
methods should only be available on a control if it holds a value of typeT | undefined
. Also, if a control was constructed with thedisabled: boolean
property set, it's type should be inferred asT | undefined
. This will also facilitate more accurate typings forFormGroup.value
where only those fields which are 'disableable' may hold a value ofT | undefined
while all other fields may only hold a value of typeT
. Here is an example illustrating the desired behaviour: