From a0adeffe227158f7d953bcba989e2e090c582b34 Mon Sep 17 00:00:00 2001 From: aymandakir-gh Date: Thu, 18 Jun 2026 10:46:30 +0200 Subject: [PATCH] fix(types): make `tsc --noEmit` clean and add a typecheck script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `npx tsc --noEmit` failed with 3× TS2802 in lib/pdf-report.test.ts: `String.fromCharCode(...bytes.slice(0, 5))` spreads a Uint8Array, which under TypeScript 5.7+ (Uint8Array became generic) "can only be iterated through with --downlevelIteration / target es2015+". Neither tsconfig knob clears it — the spread itself is the issue. CI runs lint/test/build but not tsc, so this stayed invisible. Read the leading bytes via `Array.from(bytes.slice(0, len), (b) => String.fromCharCode(b)).join("")` (small `magic()` helper, used at all three sites) and add a `"typecheck": "tsc --noEmit"` script so the project has a first-class way to catch this and it can be wired into CI. Verified: `tsc --noEmit` now exits 0, the 6 pdf-report tests still pass, and the full unit suite (228) and lint stay green. Co-authored-by: mattia-mamini-gh <281593356+mattia-mamini-gh@users.noreply.github.com> --- lib/pdf-report.test.ts | 14 +++++++++++--- package.json | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/pdf-report.test.ts b/lib/pdf-report.test.ts index abc85e3..2cdcf35 100644 --- a/lib/pdf-report.test.ts +++ b/lib/pdf-report.test.ts @@ -11,11 +11,19 @@ function allAnswers(d: Diagnostic, value: AnswerValue) { const PDF_MAGIC = "%PDF-"; +// Read the leading bytes as a string without spreading the typed array. +// `String.fromCharCode(...bytes.slice(0, 5))` trips TS2802 under TypeScript +// 5.7+ (Uint8Array became generic); Array.from with a map callback avoids the +// iteration requirement. +function magic(bytes: Uint8Array, len = 5): string { + return Array.from(bytes.slice(0, len), (b) => String.fromCharCode(b)).join(""); +} + describe.each(listDiagnostics())("buildReportPdf — $id", (diagnostic) => { it("produces a valid, non-trivial PDF for a weak result", () => { const result = scoreDiagnostic(diagnostic, allAnswers(diagnostic, 0)); const bytes = new Uint8Array(buildReportPdf(diagnostic, result)); - const head = String.fromCharCode(...bytes.slice(0, 5)); + const head = magic(bytes); expect(head).toBe(PDF_MAGIC); expect(bytes.byteLength).toBeGreaterThan(2000); }); @@ -23,7 +31,7 @@ describe.each(listDiagnostics())("buildReportPdf — $id", (diagnostic) => { it("produces a valid PDF for a strong result (no bottleneck playbook edge)", () => { const result = scoreDiagnostic(diagnostic, allAnswers(diagnostic, 4)); const bytes = new Uint8Array(buildReportPdf(diagnostic, result)); - expect(String.fromCharCode(...bytes.slice(0, 5))).toBe(PDF_MAGIC); + expect(magic(bytes)).toBe(PDF_MAGIC); expect(bytes.byteLength).toBeGreaterThan(2000); }); @@ -34,6 +42,6 @@ describe.each(listDiagnostics())("buildReportPdf — $id", (diagnostic) => { }); const result = scoreDiagnostic(diagnostic, answers); const bytes = new Uint8Array(buildReportPdf(diagnostic, result)); - expect(String.fromCharCode(...bytes.slice(0, 5))).toBe(PDF_MAGIC); + expect(magic(bytes)).toBe(PDF_MAGIC); }); }); diff --git a/package.json b/package.json index 4ed089a..9df31c1 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "build": "next build", "start": "next start", "lint": "next lint", + "typecheck": "tsc --noEmit", "test": "vitest run", "e2e": "playwright test", "screenshot": "node scripts/screenshot.mjs"