microsoft / microsoft/TypeScript
Allow subclasses to declare overloads of methods
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
Suggestion
Allow subclasses to declare an overload of a superclass method:
This would be useful with addEventListener() in order to provide the correct event type for an event name:
class MyElement extends HTMLElement {
declare addEventListener(type: 'my-event', listener: (this: MyElement, ev: MyEvent) => any, options?: boolean | AddEventListenerOptions): void;
}
🔍 Search Terms
Various combinations: addEventListener subclass declare overload method
A lot of issues were returned from queries, I could have missed something.
✅ Viability Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
⭐ Suggestion
See above. I'm not sure the reason for not allowing declare on methods currently, so hopefully that could be relaxed.
📃 Motivating Example
See above.
Right now you would have to augment the HTMLElementEventNameMap, but that makes events global, which they might not be if they don't bubble.
💻 Use Cases
See above.
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 analizzando come TypeScript gestisce i metodi declare e gli overload dei metodi ereditati. Confronta la dichiarazione addEventListener proposta per la sottoclasse con il comportamento attuale e determina le regole di controllo dei tipi necessarie. La soluzione completata dovrebbe consentire l'overload della sottoclasse senza modificare il JavaScript emesso, preservando al contempo la compatibilità con il metodo della superclasse.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100