microsoft / microsoft/TypeScript
keyword to force calling the super on any method
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
Today I faced the following code
class A {
// silly warning comment: if you override this, don't forget to call the super method to avoid memory leaks
onExit() {
// do some important cleaning stuff
}
}
class B extends A {
onExit() {
super.onExit(); // good
}
}
class C extends A {
onExit() {
// forgot to call to super.onExit = memory leaks
}
}
The problem is that, unlike a constructor, there is no way to force a method overriding another one to call the parent "super" function.
I wished we had a "concrete"* keyword to let the user know he must call the super method.
class A {
concrete onExit() {
// do some cleaning stuff
}
}
class B extends A {
onExit() {
super.onExit(); // no error
}
}
class C extends A {
// error: Declaration of derived method must contain a 'super' call
onExit() {
}
}
In another language, I could have used the final keyword to prevent overriding the method but then… no overriding allowed neither.
- "concrete" In opposition to "abstract" (for lack of a better name), other ideas: "important" or "mandatory"
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Das Issue nennt keine Implementierungsdateien, Tests oder Einstiegspunkte. Beginne damit zu prüfen, wie TypeScript Klassenmethoden parst, Vererbung prüft und fehlende super-Aufrufe meldet; für den Abschluss wären ein vereinbartes Schlüsselwort und eine vereinbarte Semantik zur Erzwingung von super-Aufrufen in überschriebenen Methoden erforderlich.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 25/100