I got two classes, one deriving from the other, and on the base class I need to check if the derived class is implementing a method with a specific name:
class Foo {
constructor() { }
childHasMethod() {
if(this.method) {
console.log('Yay');
} else {
console.log('Nay');
}
}
}
class Bar extends Foo {
constructor() {
super();
this.childHasMethod();
}
method() {
}
}
var bar = new Bar();
Even though the line if(this.method) {
is marked red on the playground, it works. But the local compiler throws a compilation error: The property 'method' does not exist on value of type 'Foo'
.
Is there a clean way to achieve what I'm trying to do?