TS2445
Property 'makeNoise' is protected and only accessible within class 'Dog' and its subclasses.
Broken Code ❌
abstract class Animal {
protected abstract makeNoise(): string;
}
class Dog extends Animal {
protected makeNoise(): string {
return 'Woof!';
}
}
const laika = new Dog();
laika.makeNoise();Fixed Code ✔️
The visibility of the makeNoise method is protected. We have to make it public if we want to call it directly from an instance of Dog:
abstract class Animal {
protected abstract makeNoise(): string;
}
class Dog extends Animal {
public makeNoise(): string {
return 'Woof!';
}
}
const laika = new Dog();
laika.makeNoise();