Here is a simplified version of my project requirements:
abstract class Parent {
protected abstract method(): any;
}
class Child extends Parent {
protected method(): any {}
protected other() {
let a: Parent = new Child()
a.method()
}
}
class Other extends Parent {
protected method(): any {}
}
The issue arises when attempting to call a.method()
, resulting in the following error message:
Property 'method' is protected and can only be accessed through an instance of class 'Child'.
It seems that the problem lies in calling a.method()
outside the actual instance a
. Even though it is called within a Child
instance, the error persists. Shouldn't instances of the same base class be able to access each other's protected methods?
How can I resolve this issue without compromising the advantages offered by using protected
? Thank you.