Skip to content

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
atscott added a commit to atscott/angular that referenced this pull request Aug 7, 2025
…lder angular versions

This fixes an issue caused by
angular#62648 for older versions of
Angular when the newest version of the language service is used. This
prevents the TCB from attempting to use the assertType when it does not
exist.

fixes angular#63046
atscott added a commit that referenced this pull request Aug 7, 2025
…lder angular versions (#63053)

This fixes an issue caused by
#62648 for older versions of
Angular when the newest version of the language service is used. This
prevents the TCB from attempting to use the assertType when it does not
exist.

fixes #63046

PR Close #63053
@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 Aug 16, 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 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