I'm trying to extend/override a protected method in a class we'll call ChildClass
a class library's protected override method tapNode
within a ParentClass
, whose method calls super
to the another protected override method tapNode
in a GrandParentClass
.
I want to override the behavior such that ChildClass
can call the grandParentClass
while extending from the ParentClass
.
To clarify, we'd have
export class ChildClass extends ParentClass {
override tapNode(node?: TreeNode): void {
custom_stuff();
super.super.tapNode(node); //What I ideally want to do but can't
}
export class ParentClass extends ChildClass {
override tapNode(node?: TreeNode): void {
[ ...
inline class-specific code
... ]
super.tapNode(node);
}
export class GrandParentClass extends ParentClass {
override tapNode(node?: TreeNode): void {
[ ...
inline class-specific code
... ]
super.tapNode(node)
}
Some approaches I've looked at so far:
I'm aware of how one can use the
prototype
method, but this seemingly only applies on public methods, NOT protected methods. (see TypeScript super.super call for more info on that approach)I'm aware of mixins and ts-mixer, but that seemingly only works if there's unique method names since you're doing a composition of classes. (see Typescript: How to extend two classes? )
I'm aware of the idea of overriding the class-specific code if it's put into it's own method, but that only applies when the code is separated out into it's own method, NOT when it's inline. (see https://stackoverflow.com/a/56536651/314780 as an example).
I'm aware you generally don't want to do this!