Take a look at the following code snippet:
class Salutation {
message: string;
constructor(text: string) {
this.message = text;
}
greet() {
return "Bonjour, " + this.message;
}
}
class Greetings extends Salutation {
constructor(text: string) {
super(text);
}
greet() {
return "Hola " + super.greet();
}
}
let salutation = new Greetings("mundo");
console.log(salutation.greet()); // Hola Bonjour, mundo
console.log((<Salutation> salutation).greet()); // Hola Bonjour, mundo
The expectation is that the second log should display Bonjour, mundo
.
Upon inspecting the transpiled Javascript
code, it appears to be an exact match which isn't surprising.
The real query lies in how you can cast the salutation
object to its extended class.