There is a small TypeScript module for previewing a profile badge in Node.js. After a recent PR, the panel started behaving strangely in two scenarios: some invalid responses are suddenly accepted as valid, and re-editing a draft sometimes changes the original template for subsequent runs. A diff review is needed to find the causes.
Context and requirements:
strict=true, module and moduleResolution: nodenext.npx tsc -p tsconfig.json, then node dist/demo.js.buildBadgePreview(input) accepts arbitrary JSON-like unknown and returns an object { title: string; tags: string[] }.name must be a non-empty string after trim();tags must be an array of non-empty strings after trim();title in the format "<name> • <number of tags>".createDraft(template) must create an independent draft based on the profile template; changing the draft must not change the original template or other drafts.Reproduction steps:
npx tsc -p tsconfig.json.node dist/demo.js.Assumption: the input comes from an external source and is not guaranteed to have a correct shape.
TypeScript 5.8, strict=true, Node.js 22.16.0, ES modules; compile with tsc, run the generated JavaScript through Node; no third-party libraries
Use line comments to explain the problem, its impact, the fix and how to test it.