Review generated job runner

from Strict mode
TypeScript 6 advanced 6 min 4 issues to find

Review this generated strict-mode job runner before it is used in a service.

Load one job from untrusted JSON, validate its fields, prevent execution before loading, pass no service token to the handler, and report any thrown value safely.

TypeScript
type Job = {
  name: string;
  timeoutMs: number;
  serviceToken: string;
};

declare const readConfig: () => string;

class Runner {
  private config!: Job;

  load(): void {
    this.config = JSON.parse(readConfig()) as Job;
  }

  run(handler: (job: Job) => void): void {
    try {
      handler(this.config);
    } catch (error) {
      console.log((error as Error).message);
    }
  }
}

generated code is illustrative, not from any one model

Open in playground
Report an error