'typescript - define a string variable as a method of a class

lets say i want to create an abstract class with a factory class in it:

abstract class BaseA {}

class A extends BaseA {
    someMethod(...) {}
    
    ...
}

abstract class BaseB<T extends typeof BaseA> {
    protected abstract aClass: InstanceType<T>

    public someFunction(methodName: keyof InstanceType<T>) {
        ...
        const result = this.aClass[methodName](...) //This line here not passing TSC
    }
}

class B extends BaseB {
    protected aClass = new A()
}

how do i type a string to be a class method - and be able still to run it?

at the moment, for the this.aClass[methodName](...) i get "This expression is not callable. Type 'unknown' has no call signatures"

thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source