If i have:
var greeter: Greeter = new Sausage();
And both the Greeter class and Sausage class have the same functions and properties in them, the variable greeter will quite happily be filled up with a Sausage... How can i stop this?
For example, the following code compiles fine :(
class Greeter {
greeting: string;
constructor(message: string) {
this.greeting = message;
}
greet() {
return "Hello, " + this.greeting;
}
}
class Sausage {
size: number;
name: string;
greeting: string;
constructor() {
this.size = this.SausageLogic();
}
private SausageLogic(): number {
return this.size * 3;
}
greet() {
return "Hello, ";
}
}
var greeter: Greeter = new Sausage();