I am creating a job system and I want my DSL to look like the following:
@ScheduledTaskProcessor()
export class ScoringProcessor extends AbstractScheduledProcessor<ScoringInput> {
static cron = CRON_NIGHTLY_FIRST_BATCH
async process(args: ScoringInput) {
// does some work
}
}
i would love AbstractScheduledProcessor to look like the following:
export abstract class AbstractScheduledProcessor<T> {
abstract static cron: string;
abstract process(args: T): Promise<void>
... other non abstract method follow ...
but i get: TS1243: 'static' modifier cannot be used with 'abstract' modifier.
Can anyone suggest a path forward. Perhaps I can use my class decorator as a HOF to create the class with the static property.
FYI my ScheduledTaskProcessor decorator function curently looks like this:
import { Container } from 'typedi'
export function ScheduledTaskProcessor(): ClassDecorator {
return function(target) {
console.log('registering: ', target)
Container.of('ScheduledTaskProcessor').set(target.name, target)
}
}
You can make sure that you have to set a static value with decorators. The approach would look like this:
Playground