Consider the following:
export type JSONable = Record<string, string | number>
export type Processable = {
process(args?: JSONable): Promise<void>
}
abstract class AbstractTaskProcessor<T extends JSONable> implements Processable {
abstract process(args?: T): Promise<void>
}
this is part of my job system. But sometimes for testing I want to test the process method right away, so I wanted to add a static helper method like so
abstract class AbstractTaskProcessor<T extends JSONable> implements Processable {
abstract process(args?: T): Promise<void>
static runNow(args?: T): Promise<void> {
const instance = new this()
return instance.process(args)
}
}
but i get a TS2511: Cannot create an instance of an abstract class.
I would like the DSL to be something like ...
MyTaskProcessor.runNow({accountId: 123123, accountName: 'Lorum' })
Does anyone have a good pattern for this?
I am on TS 4.2