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

Skip to content

fix(forms): fix FormRecord type inference #50752

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

EmmanuelRoux
Copy link
Contributor

@EmmanuelRoux EmmanuelRoux commented Jun 17, 2023

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?

Issue Number: #50751

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@pullapprove pullapprove bot requested a review from AndrewKushnir June 17, 2023 18:32
@JeanMeche JeanMeche added area: forms forms: Controls API Issues related to AbstractControl, FormControl, FormGroup, FormArray. labels Jun 17, 2023
@ngbot ngbot bot modified the milestone: Backlog Jun 17, 2023
@EmmanuelRoux EmmanuelRoux force-pushed the fix-formrecord-type-inference branch from 46d5b75 to 1bd1ae6 Compare June 17, 2023 19:00
Updates type inference in `ɵElement` to make `FormRecord` take precedence over `FormGroup`
Add a marker property to `FormRecord` to make its type actually different from `FormGroup`
@JeanMeche
Copy link
Member

cc @dylhunn You might wanna take a look at this 👍

Add ɵ as prefix to internal property
Simplify brand property and avoid value assignment
@AndrewKushnir AndrewKushnir requested review from dylhunn and removed request for AndrewKushnir June 18, 2023 21:21
@EmmanuelRoux
Copy link
Contributor Author

EmmanuelRoux commented Aug 16, 2023

Up 🙂 @dylhunn

@dylhunn
Copy link
Contributor

dylhunn commented Aug 21, 2023

Interesting. Can you show an example of an inference that would have been broken under the previous regime? It would be good to add it to typed_integration_spec as well, to document the change and prevent regressions.

@EmmanuelRoux
Copy link
Contributor Author

@dylhunn you can take a look at the failed test in this PR : #50750

A FormRecord is inferred as FormGroup.
While this is not incorrect technically, because FormRecord actually extends FormGroup (and this is the reason of bad inference), it is probably unexpected.
The helper type ɵElement should probably infer it to FormRecord instead.

@JeanMeche
Copy link
Member

@EmmanuelRoux If this PR provides a fix it should also introduce a previously broken test !

@EmmanuelRoux
Copy link
Contributor Author

EmmanuelRoux commented Aug 29, 2023

@JeanMeche This is why I provided a link to #50750 :

Currently, this does NOT break anything, because FormRecord type is actually compatible with FormGroup (and vice versa). See :

type X = ɵElement<FormRecord<FormControl<string>>, null>;
// X is currently inferred as FormGroup<{[p: string]: FormControl<string>}>

const formGroupX: X = null!;
const formGroupY: FormGroup<{[p: string]: FormControl<string>}> = a; 
const formRecordZ: FormRecord<FormControl<string>> = a; // <-- Currently no error, because FormGroup can be assigned to FormRecord

BUT, if FormRecord would define some specific signature it would become incompatible with FormGroup:

// Let's imagine FormRecord has a new method, for example:
export interface FormRecord<TControl> {
  // ...
  someMethod(): TControl;
}

// Then this would break (as expected) :

const formGroupX: X = null!;
const formGroupY: FormGroup<{[p: string]: FormControl<string>}> = a; 
const formRecordZ: FormRecord<FormControl<string>> = a; // <-- Error, because FormGroup cannot be assigned to FormRecord

This is exactly what the PR #50750 aims to introduce.

@JeanMeche
Copy link
Member

JeanMeche commented Aug 29, 2023

This is for the sake of commit tree grooming. That we'd like to have tests covering bugfixes / feature introductions.

Either this PR should introduce new test, which shows the fix its bringing or the PR should be merged with #50750.

@EmmanuelRoux
Copy link
Contributor Author

@JeanMeche @dylhunn merged with #50750

@EmmanuelRoux
Copy link
Contributor Author

Any update on this PR or #50750 please ?

@JeanMeche
Copy link
Member

I'll close this in favor of #50750 which is getting reviewed and tested.

@JeanMeche JeanMeche closed this May 17, 2024
@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 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: forms forms: Controls API Issues related to AbstractControl, FormControl, FormGroup, FormArray.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants