Imagine a scenario where I have a simple class that extends other classes, and an object of functions that I am passing to class B
const actions = {
doSomething: (this: B, foo: boolean) => {
console.log('from do something', this.text, foo);
}
}
class B {
actions = actions;
text: string;
constructor() {
this.text = 'abc';
}
}
class A extends B {
runAction(foo) {
this.actions.doSomething(false);
}
}
const instance = new A();
instance.runAction(); // 'from do something, undefined, false'
The TypeScript compiler is also indicating that the this
context is incorrect when called from within runAction
Is there a more efficient way to achieve this functionality?
We need access to the class data for over 500 actions without passing arguments through each one individually.