Can you help me find the correct index signature for this particular class?
class MyClass {
[index: string]: Promise<void> | Promise<MyType>; // not working
public async methodOne (): Promise<void> { ... }
public async methodTwo (): Promise<MyType> { ... }
}
I need to be able to call a method on this class using the string name of the method:
myClassInstance[stringNameOfMethodOne]()
There are two TypeScript errors that I am encountering. The error on the method definition states:
Property 'methodOne' of type '() => Promise<void>' is not assignable to 'string' index type 'Promise<void> | Promise<MyType>'
The error relating to the usage of the method is:
This expression is not callable. No constituent of type 'Promise<MyType> | Promise<void>' is callable.
I have successfully done similar tasks in JavaScript, but TypeScript's index signatures are proving to be more challenging.