microsoft / microsoft/TypeScript
TypeScript not enforcing the return type of optional methods defined in interfaces implemented by parents of classes
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
TypeScript Version: 3.5.0 (Also tried 3.4.1, 3.0.1, and 2.4.1)
Search Terms: Inheritance, interface, return type, parent, child, override, overload, abstract, optional method, optional interface, implements, extends
Code
interface Mx {
aMethod?(): number;
}
abstract class Base implements Mx {
}
class Child extends Base {
public aMethod() {
return 'hello world';
}
}
Expected behavior:
TypeScript tells me that the return type for Child#aMethod is wrong.
This behaviour is achieved if I add implements Mx on the Child class.
Actual behavior:
TypeScript tells me nothing! It feels that Child#aMethod is well within its rights to return a string.
Playground Link: linky!
Related Issues: I didn't really find any similar looking issues?
The result is this could maybe relate to #22815
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
Beginne damit, das Beispiel im verlinkten TypeScript Playground zu reproduzieren, und vergleiche es dann mit der Version, in der Child Mx explizit implementiert. Die Arbeit ist abgeschlossen, wenn TypeScript den inkompatiblen Rückgabetyp string für Child#aMethod meldet, ohne die redundante implements-Klausel zu erfordern.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100