Skip to content

fix(compiler-cli): infer type of event target for void elements #62648

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
wants to merge 3 commits into from

Conversation

crisbeto
Copy link
Member

Currently we infer the target of DOM events to be EventTarget | null which is consistent with the built-in types for addEventListener. This is due to the fact that users can dispatch custom events, or the event might've bubbled. However, this typing is also inconvenient for some other common use cases like <input (input)="query($event.target.value)">, because we don't have the ability to type cast in a template.

These changes aim to make some of the cases simpler by inferring the type of $event.target if the event is bound on a void element which guarantees that it couldn't have bubbled.

@crisbeto crisbeto added the target: patch This PR is targeted for the next patch release label Jul 15, 2025
@angular-robot angular-robot bot added area: compiler Issues related to `ngc`, Angular's template compiler area: core Issues related to the framework runtime labels Jul 15, 2025
@ngbot ngbot bot added this to the Backlog milestone Jul 15, 2025
@crisbeto crisbeto force-pushed the narrow-event-type branch 3 times, most recently from 7a37a61 to 7f5efed Compare July 15, 2025 16:51
@crisbeto crisbeto marked this pull request as ready for review July 15, 2025 18:46
@crisbeto crisbeto requested a review from atscott July 15, 2025 18:47
crisbeto added 3 commits July 16, 2025 09:42
Updates the HTML AST to indicate whether a specific element is a void element.
Adds the `ɵassertType` function that will be used during type checking to assert the type of a value.
Currently we infer the target of DOM events to be `EventTarget | null` which is consistent with the built-in types for `addEventListener`. This is due to the fact that users can dispatch custom events, or the event might've bubbled. However, this typing is also inconvenient for some other common use cases like `<input (input)="query($event.target.value)">`, because we don't have the ability to type cast in a template.

These changes aim to make some of the cases simpler by inferring the type of `$event.target` if the event is bound on a void element which guarantees that it couldn't have bubbled.
@crisbeto crisbeto force-pushed the narrow-event-type branch from 7f5efed to 436d83a Compare July 16, 2025 07:43
@crisbeto crisbeto removed the request for review from atscott July 16, 2025 07:43
@crisbeto
Copy link
Member Author

Passing TGP

@crisbeto crisbeto added the action: merge The PR is ready for merge by the caretaker label Jul 16, 2025
@crisbeto
Copy link
Member Author

This PR was merged into the repository by commit 527bd77.

The changes were merged into the following branches: main, 20.1.x

crisbeto added a commit that referenced this pull request Jul 16, 2025
…2648)

Updates the HTML AST to indicate whether a specific element is a void element.

PR Close #62648
crisbeto added a commit that referenced this pull request Jul 16, 2025
Adds the `ɵassertType` function that will be used during type checking to assert the type of a value.

PR Close #62648
crisbeto added a commit that referenced this pull request Jul 16, 2025
Currently we infer the target of DOM events to be `EventTarget | null` which is consistent with the built-in types for `addEventListener`. This is due to the fact that users can dispatch custom events, or the event might've bubbled. However, this typing is also inconvenient for some other common use cases like `<input (input)="query($event.target.value)">`, because we don't have the ability to type cast in a template.

These changes aim to make some of the cases simpler by inferring the type of `$event.target` if the event is bound on a void element which guarantees that it couldn't have bubbled.

PR Close #62648
@crisbeto crisbeto closed this in acdb8d6 Jul 16, 2025
crisbeto added a commit that referenced this pull request Jul 16, 2025
Adds the `ɵassertType` function that will be used during type checking to assert the type of a value.

PR Close #62648
crisbeto added a commit that referenced this pull request Jul 16, 2025
Currently we infer the target of DOM events to be `EventTarget | null` which is consistent with the built-in types for `addEventListener`. This is due to the fact that users can dispatch custom events, or the event might've bubbled. However, this typing is also inconvenient for some other common use cases like `<input (input)="query($event.target.value)">`, because we don't have the ability to type cast in a template.

These changes aim to make some of the cases simpler by inferring the type of `$event.target` if the event is bound on a void element which guarantees that it couldn't have bubbled.

PR Close #62648
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action: merge The PR is ready for merge by the caretaker area: compiler Issues related to `ngc`, Angular's template compiler area: core Issues related to the framework runtime target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy