Generic typing used for "input" event listeners
#54,336 opened on 2023幎5æ21æ¥
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
# Bug Report
ð Search Terms
typescript input event
ts InputEvent
typescript addEventListener("input",
ð Version & Regression Information
I just found it today but verified it was present back to 3.3.3333
I also verified it existed on nightly
Please keep and fill in the line that best applies:
This is the behavior in every version I tried, and I reviewed the FAQ for entries about... I looked at entries about event listeners, HTML element types, and callbacks.
⯠Playground Link
ð» Code
// Error on the typing of the event parameter
(null as any as HTMLInputElement).addEventListener("input", (e: InputEvent) => {});
(null as any as HTMLTextAreaElement).addEventListener("input", (e: InputEvent) => {});
ð Actual behavior
The sample code fails to compile because the input event is always typed as an Event, not InputEvent.
ð Expected behavior
For most elements, the callback event should be Event, but for <textarea> and <input>, it should be InputEvent.
For and elements that accept text input (type=text, type=tel, etc.), the interface is InputEvent; for others, the interface is Event.
According to the W3C spec, it should be InputEvent for any element that is contenteditable. I don't know that you can trigger an input event on other non-contenteditable elements so perhaps the event type can be made InputEvent, regardless of the element type it is called on.