Review this generated parser and event summarizer.
Parse an untrusted job event, accept only valid literal-tagged payloads, and return a descriptive line containing the job id and state-specific detail with exhaustive handling and no unnecessary work.
TypeScript
type JobEvent =
| { kind: "started"; jobId: string }
| { kind: "completed"; jobId: string; resultUrl: string }
| { kind: "failed"; jobId: string; message: string };
function parseEvent(raw: string): JobEvent {
const event = JSON.parse(raw) as JobEvent;
return event;
}
function summarize(event: JobEvent): string {
const copy = { ...event };
switch (copy.kind) {
case "completed":
return copy.resultUrl;
case "failed":
return copy.message;
default:
return "started";
}
}
generated code is illustrative, not from any one model