Review generated job registry

from satisfies operator
TypeScript 6 advanced 6 min 4 issues to find

Review this generated environment-driven job registry.

Load exactly the cleanup and invoice jobs from environment JSON, reject malformed configuration, and execute a requested job without silently changing behavior.

TypeScript
type JobName = "cleanup" | "invoice";
type Job = {
  schedule: "hourly" | "daily";
  retries: number;
  run(input: unknown): void;
};

declare const env: { JOBS?: string };
const rawJobs = JSON.parse(env.JOBS ?? "{}");
const jobs = rawJobs satisfies Record<string, Job>;

const fallback = {
  schedule: "daily",
  retries: 0,
  run: (_input: unknown) => undefined,
} as const satisfies Job;

function execute(name: JobName, input: unknown): void {
  const job = jobs[name] ?? fallback;
  job.run(input);
}

execute("cleanup", { tenantId: "acme" });

generated code is illustrative, not from any one model

Open in playground
Report an error