fix(angular): strict template event bindings #24314
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull request checklist
Please check if your PR fulfills the following requirements:
npm run build
) was run locally and any changes were pushednpm run lint
) has passed locally and any fixes were made for failuresPull request type
Please check the type of change your PR introduces:
What is the current behavior?
The Angular bindings for the web components are incorrectly type checked by Angular Language Service with
strictTemplates
enabled. The previous usage offromEvent
, resulted in the types ofaddEventListener
being applied to output events when using template event binding:(ionSlideDidChange)="doSlideChange($event)"
instead ofCustomEvent
.Issue Number: #24245
What is the new behavior?
The Angular bindings no longer need to use
fromEvent
to create an observable from the event source. They instead generate with Angular's@Output()
decorator, which correctly associates the type checking for the output events.Does this introduce a breaking change?
This change will prevent a non-standard pattern for binding to output events in class implementations, but alternative patterns exist to provide the same solution.
Before this would work:
After, implementers will need to use
rxjs
to convert the DOM event:Note: In both implementations the subscriptions are always hot and should be tore down later. This is the downside of this non-standard pattern. With the template binding syntax, Angular will automatically tear down the subscription for you.
I spoke with Mike & other GDEs and this pattern is very rare.
Other information
Dependent on this PR to adjust the generated proxy output: ionic-team/stencil-ds-output-targets#209
Will need a prerelease version to validate outside of locally packing.
Also this PR will need to rebase with the changes after #24313 (likely rebasing the PR in stencil-ds-output-targets).