Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(forms): allow control state as reset argument for FormGroup #55860

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

Closed

Conversation

bougwal
Copy link

@bougwal bougwal commented May 17, 2024

fix(forms): Allow ControlState as reset arguments for FormGroup/FormRecord

This change also decorelate the reset type argument from TValue by adding a 3rd generic parameter to AbstractControl.
This improves the typings overall.

This PR closes #55577.

@pullapprove pullapprove bot requested a review from dylhunn May 17, 2024 17:16
@bougwal bougwal force-pushed the fix/form-group-state-type-inference branch from 319e8c2 to 46312f2 Compare May 17, 2024 18:07
Copy link
Member

@JeanMeche JeanMeche left a comment

Choose a reason for hiding this comment

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

See my suggestions.

@JeanMeche JeanMeche added action: review The PR is still awaiting reviews from at least one requested reviewer area: forms labels May 17, 2024
@ngbot ngbot bot added this to the Backlog milestone May 17, 2024
@bougwal bougwal force-pushed the fix/form-group-state-type-inference branch 3 times, most recently from 23aa90b to 590481c Compare May 17, 2024 19:09
@bougwal bougwal force-pushed the fix/form-group-state-type-inference branch from 590481c to 8fdb80f Compare May 17, 2024 19:28
@bougwal bougwal requested a review from JeanMeche May 17, 2024 19:30
@JeanMeche
Copy link
Member

Thank for the changes Walid !
We'll do some checks against the Google codebase and we'll let you know if we can go forward with the change.

@dylhunn
Copy link
Contributor

dylhunn commented May 17, 2024

We're investigating an issue illustrated by the following snippet:

function valueChangesWrapper<T>(control: AbstractControl<T>) {
  return control.valueChanges;
}
const fg = new FormGroup({foo: new FormControl('')});
fg.valueChanges;
const a = valueChangesWrapper(fg);

Notice that the inferred type of valueChangesWrapper inappropriately includes FormControlState. We think this is due to type unification of FormGroup.reset with AbstractControl.reset.

This is super tricky to debug/understand.

@JeanMeche JeanMeche force-pushed the fix/form-group-state-type-inference branch from 8fdb80f to eeab1c7 Compare May 17, 2024 23:30
@JeanMeche
Copy link
Member

I've allowed myself to push the changes to fix the issues that were brought up by testing the fix against Google's code base.

Basically what happens is that changing the reset() signature had implicationg on the TValue generic of AbstractControl.

@JeanMeche JeanMeche force-pushed the fix/form-group-state-type-inference branch from eeab1c7 to 144f0cf Compare May 17, 2024 23:43
@JeanMeche JeanMeche changed the title fix(forms): Type inference issue on ɵFormGroupValue in formGroup.reset due to usage of FormControlState<T> fix(forms): allow control state as reset argument for FormGroup May 18, 2024
@JeanMeche JeanMeche force-pushed the fix/form-group-state-type-inference branch 2 times, most recently from 6bfaa7c to 51f080c Compare May 18, 2024 00:57
@JeanMeche JeanMeche added the target: minor This PR is targeted for the next minor release label May 18, 2024
@JeanMeche JeanMeche force-pushed the fix/form-group-state-type-inference branch from 51f080c to bd06239 Compare June 12, 2024 21:41
@GuillaumeCz
Copy link

Hello !

Any update on this PR ? ;)

@JeanMeche JeanMeche force-pushed the fix/form-group-state-type-inference branch from bd06239 to e309324 Compare May 2, 2025 11:03
@pullapprove pullapprove bot requested a review from devversion May 2, 2025 11:03
@devversion devversion requested review from kirjs and removed request for devversion and dylhunn May 5, 2025 06:27
@kirjs
Copy link
Contributor

kirjs commented May 6, 2025

I'm not super familiar with this area,
Do I understand correctly, that this behavior is something that is implemented, but wasn't supported on the type level?
How would it disambiguate between an object that has a disabled prop, and value props, and setting up state?

@JeanMeche
Copy link
Member

JeanMeche commented May 7, 2025

TGP is "green".

@JeanMeche
Copy link
Member

@kirjs to answer your question, you'd have to do the same as you would declare such control: the state like structure must be defined in a state.

const fc = new FormControl({ value: {value: 'test', disabled: true}, disabled: true });
fc.reset({ value: {value: 'xx', disabled: false}, disabled: true })
console.log(fc.value); // {value: 'xx', disabled: false}

Copy link
Member

@JeanMeche JeanMeche left a comment

Choose a reason for hiding this comment

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

We wrote the changes with @dylhunn.

…rmRecord`

This change also decorelate the `reset` type argument from `TValue` by adding a 3rd generic parameter to `AbstractControl`.
This improves the typings overall.
@JeanMeche JeanMeche force-pushed the fix/form-group-state-type-inference branch from e309324 to 5b9fd62 Compare May 7, 2025 15:23
@thePunderWoman thePunderWoman marked this pull request as draft May 21, 2025 15:28
@JeanMeche JeanMeche marked this pull request as ready for review May 21, 2025 15:51
Copy link
Contributor

@kirjs kirjs left a comment

Choose a reason for hiding this comment

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

Reviewed-for: public-api

@pullapprove pullapprove bot requested a review from crisbeto May 21, 2025 15:57
Copy link
Contributor

@thePunderWoman thePunderWoman left a comment

Choose a reason for hiding this comment

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

reviewed-for: public-api

@thePunderWoman thePunderWoman added action: presubmit The PR is in need of a google3 presubmit action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer action: presubmit The PR is in need of a google3 presubmit labels May 21, 2025
@thePunderWoman
Copy link
Contributor

This PR was merged into the repository by commit 610bebf.

The changes were merged into the following branches: main

@angular-automatic-lock-bot
Copy link

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 Jun 21, 2025
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 target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FormGroup.reset() input typings are incorrect
6 participants