Skip to content

Conversation

@crisbeto
Copy link
Member

Fixes the following issues with how we type check event listeners:

refactor(compiler): allow name parsing logic to be reused

Moves the logic for parsing event names out into methods on the BindingParser so we don't have to duplicate it. Also updates the types to more accurately represent the runtime value.

fix(compiler-cli): set correct target when type checking events

Currently the TCB generation code doesn't handle targeted events (e.g. (document:click)) which ends up binding to the current element and can have type inference implications. These changes take the event's target into account.

fix(compiler-cli): correctly parse event name in HostListener

Fixes that we weren't accounting for targeted events when creating the AST for @HostListener-decorated members.

Moves the logic for parsing event names out into methods on the `BindingParser` so we don't have to duplicate it. Also updates the types to more accurately represent the runtime value.
Currently the TCB generation code doesn't handle targeted events (e.g. `(document:click)`) which ends up binding to the current element and can have type inference implications. These changes take the event's `target` into account.
Fixes that we weren't accounting for targeted events when creating the AST for `@HostListener`-decorated members.
@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer target: major This PR is targeted for the next major release labels Mar 26, 2025
@crisbeto crisbeto requested a review from devversion March 26, 2025 09:55
@angular-robot angular-robot bot added the area: compiler Issues related to `ngc`, Angular's template compiler label Mar 26, 2025
@ngbot ngbot bot added this to the Backlog milestone Mar 26, 2025
constructor(
name: string,
targetOrPhase: string,
targetOrPhase: string | null,
Copy link
Member

Choose a reason for hiding this comment

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

OOC: was the value before just empty if there isn't a target or phase?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was a null that was non-null-asserted to any.

@crisbeto crisbeto added 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 labels Mar 26, 2025
@alxhub
Copy link
Member

alxhub commented Mar 27, 2025

This PR was merged into the repository by commit 1e6faad.

The changes were merged into the following branches: main

@alxhub alxhub closed this in ec8c8f8 Mar 27, 2025
alxhub pushed a commit that referenced this pull request Mar 27, 2025
Currently the TCB generation code doesn't handle targeted events (e.g. `(document:click)`) which ends up binding to the current element and can have type inference implications. These changes take the event's `target` into account.

PR Close #60561
alxhub pushed a commit that referenced this pull request Mar 27, 2025
Fixes that we weren't accounting for targeted events when creating the AST for `@HostListener`-decorated members.

PR Close #60561
@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 Apr 27, 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: compiler Issues related to `ngc`, Angular's template compiler target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants