I have an object and I want to dynamically call a method on it.
Having typechecking would be nice but that maybe impossible. But I can't even get it to compile at all currently:
const key: string = 'someMethod'
const func = this[key]
func(msgIn)
gives me this error...
Element implicitly has an 'any' type
because expression of type 'any' can't be used
to index type 'TixBot'.
I tried some other type options without success.
const key: any = cmd.func
const func: any = this[key]
Apart from @ts-ignore
how could I solve this?
I was wondering if I can use .call()
or bind
to somehow work around it?