Siehe das Vererbungsbeispiel vom Spielplatz auf der TypeScript-Site:
class Animal {
public name;
constructor(name) {
this.name = name;
}
move(meters) {
alert(this.name + " moved " + meters + "m.");
}
}
class Snake extends Animal {
constructor(name) {
super(name);
}
move() {
alert("Slithering...");
super.move(5);
}
}
class Horse extends Animal {
constructor(name) {
super(name);
}
move() {
alert(super.name + " is Galloping...");
super.move(45);
}
}
var sam = new Snake("Sammy the Python");
var tom: Animal = new Horse("Tommy the Palomino");
sam.move();
tom.move(34);
Ich habe eine Codezeile geändert: die Warnung in Horse.move(). Dort möchte ich zugreifen super.name, aber das kommt gerade zurück undefined. IntelliSense schlägt vor, dass ich es verwenden kann und TypeScript gut kompiliert, aber es funktioniert nicht.
Irgendwelche Ideen?