Skip to content

feat(core): narrower event binding types #39120

@LayZeeDK

Description

@LayZeeDK

🚀 feature request

Relevant Package

This feature request is for @angular/core.

Description

With the strictTemplates: true Angular compiler setting, it can be tough to deal with native $event in event bindings.

Describe the solution you'd like

I would like to be able to do

  • <input (input)="onInput($event.target.value)"> where $event is InputEvent or $event.target/$event.currentTarget is HTMLInputElement
  • <button (click)="onClick($event.target.textContent)>Hello <span>World</span></button> where $event is MouseEvent and $event.target/$event.currentTarget is HTMLButtonElement

Describe alternatives you've considered

We can use $any() casting, but that is counterintuitive when having strictTemplates compilation enabled.

Maybe $event.currentTarget is easier to work with than $event.target for this feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: coreIssues related to the framework runtimecross-cutting: types

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions