TypeScript sitesindeki oyun alanından miras örneğine bakın:
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);
Bir satır kodu değiştirdim: içindeki uyarı Horse.move(). Oraya erişmek istiyorum super.nameama bu sadece geri dönüyor undefined. IntelliSense, onu kullanabileceğimi ve TypeScript'in iyi derlendiğini öneriyor, ancak işe yaramıyor.
Herhangi bir fikir?