microsoft / microsoft/TypeScript
Generic typing used for "input" event listeners
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
# 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 <textarea> 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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con i typings di addEventListener esercitati dal codice fornito di TypeScript Playground per HTMLInputElement e HTMLTextAreaElement. Determina come debba essere tipizzato l’evento input per questi elementi, mantenendo Event per gli altri elementi, quindi verifica che l’esempio venga compilato e che il comportamento più generale di contenteditable sia coperto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- frontend
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100