I am currently working with this TypeScript code snippet:
abstract class Base {
static actions:Record<string,unknown>
static getActions () {
return this.actions
}
}
class Sub extends Base {
static actions = {
bar:(bar:string) => {
return 'bar ' + bar
}
}
}
const sample = Sub.getActions()
sample.bar('baz') //=> 'bar baz'
The code functions as expected when executed, but I encounter an error in VSCode regarding the sample.bar('baz')
method
unknown
This expression is not callable. Type '{}' has no call signatures.'.
Additionally, there is no Intellisense support for the return of Sub.getActions()
. It seems that the issue may stem from how I have typed the actions
property in the base class.
How can I correctly type this scenario so that VSCode recognizes it? Are there alternative approaches to achieve similar functionality?