Skip to content

feat(forms): support a generic type for ControlValueAccessor#31801

Closed
jonkoops wants to merge 1 commit intoangular:masterfrom
jonkoops:feature/generic-control-value-accessor
Closed

feat(forms): support a generic type for ControlValueAccessor#31801
jonkoops wants to merge 1 commit intoangular:masterfrom
jonkoops:feature/generic-control-value-accessor

Conversation

@jonkoops
Copy link

@jonkoops jonkoops commented Jul 23, 2019

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?

ControlValueAccessor has no support for a generic type, meaning that when implemented all methods assume a type of any.

What is the new behavior?

ControlValueAccessor now accepts an optional generic type so that all methods that are implemented from this interface receive the appropriate type.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

This PR is related to the following issues and requests:

@jonkoops jonkoops requested a review from a team July 23, 2019 15:30
@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here (e.g. I signed it!) and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@jonkoops
Copy link
Author

Unfortunately it looks like these changes will actually incur a breaking change to the types of the public API. In some classes where ControlValueAccessor was implemented the function signatures for registerOnChange and registerOnTouched were more extensively typed. These were also incorrectly typed as returning an empty interface instead of the expected void return type.

I've fixed the typings for the classes that implement ControlValueAccessor internally, so these are no longer a problem. Existing applications that implement ControlValueAccessor incorrectly should fail to compile with TypeScript providing information about how to fix the problem.

Perhaps adding a code mod would be appropriate to fix the problem automatically?

@ShawnOzark
Copy link

ShawnOzark commented Nov 9, 2019

So does this mean without the angular teams coordinating between the angular + angular/material libraries this is stuck? Is there a PR on the material side to correct this? This is arguably more important than the AbstractControl generic issues since without the ControlValueAccessor having generics you have no template side compile time safety, making the AbstractControl generics unsafe.

EDIT: Also, on the topic of this change for Template side compile time safety, should we break out the default value accessor to be more type specific based on the input type? (type number is a generic of number, type text a generic of string, type checkbox a generic of Boolean) It looks like its selector can be targeted like that.

@jonkoops
Copy link
Author

@ShawnOzark That is essentially correct, however this change would not simply impact Angular Material but all libraries that make use of the ControlValueAccessor.

@AndrewKushnir
Copy link
Contributor

Closing this PR in favor of more recent #38406 and #38906. Thank you.

@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 Jan 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants