TS2445

error TS2445: Property ‘makeNoise’ is protected and only accessible within class ‘Dog’ and its subclasses.

Bad Code ❌

1
2
3
4
5
6
7
8
9
10
11
12
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:

1
2
3
4
5
6
7
8
9
10
11
12
abstract class Animal {
protected abstract makeNoise(): string;
}

class Dog extends Animal {
public makeNoise(): string {
return 'Woof!';
}
}

const laika = new Dog();
laika.makeNoise();

Video: https://youtu.be/62J_eQsK0e0?t=876