Is there a way to use TypeScript's abstract class
to enforce defining functions and variables within the class for implementation?
abstract class Animal {
sound: string;
speak() {
console.log(this.sound);
}
}
class Cat extends Animal {
sound = 'meow';
}
const c = new Cat()
c.speak()
The Cat
class should require the property sound
and inherit the method speak
from the Animal
class.
Can something like this be achieved?
Despite not being evident in this example, I specifically need to utilize an abstract class
.