fix: remove unnecessary 'as any' casts and add proper types to templates
Some checks failed
Build & Deploy to Staging / Build & Deploy to Staging (push) Failing after 4m29s
Some checks failed
Build & Deploy to Staging / Build & Deploy to Staging (push) Failing after 4m29s
- Replace (req as any).requestId with req.requestId in index.ts, recover.ts, email-change.ts - Replace (err as any).status with proper Record<string, unknown> narrowing in error handler - Add InvoiceData, ReceiptData, ContactInfo, InvoiceItem, ReceiptItem interfaces to templates.ts - Replace all 'any' params in template functions with proper types - Add type-safety regression tests (grep-based) - 818 tests pass, tsc --noEmit: 0 errors
This commit is contained in:
parent
4057bd9d91
commit
2e8a240654
7 changed files with 109 additions and 32 deletions
|
|
@ -1,10 +1,10 @@
|
|||
import { describe, it, expect } from "vitest";
|
||||
import { renderTemplate, templates } from "../services/templates.js";
|
||||
import { renderTemplate, templates, TemplateData } from "../services/templates.js";
|
||||
|
||||
// Access esc via rendering — test that HTML entities are escaped in output
|
||||
describe("Template rendering", () => {
|
||||
it("throws for unknown template", () => {
|
||||
expect(() => renderTemplate("nonexistent", {})).toThrow("not found");
|
||||
expect(() => renderTemplate("nonexistent", {} as TemplateData)).toThrow("not found");
|
||||
});
|
||||
|
||||
it("invoice renders with correct totals", () => {
|
||||
|
|
|
|||
31
src/__tests__/type-safety.test.ts
Normal file
31
src/__tests__/type-safety.test.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { describe, it, expect } from "vitest";
|
||||
import { execSync } from "child_process";
|
||||
import path from "path";
|
||||
|
||||
describe("Type safety", () => {
|
||||
const srcDir = path.resolve(__dirname, "..");
|
||||
|
||||
it("should not use (req as any).requestId in production code — Express.Request is already augmented", () => {
|
||||
const result = execSync(
|
||||
`grep -r "(req as any)\\.requestId" --include="*.ts" --exclude-dir=__tests__ "${srcDir}" || true`,
|
||||
{ encoding: "utf-8" }
|
||||
);
|
||||
expect(result.trim()).toBe("");
|
||||
});
|
||||
|
||||
it("should not use (err as any) — use proper type narrowing instead", () => {
|
||||
const result = execSync(
|
||||
`grep -r "(err as any)" --include="*.ts" "${srcDir}" --exclude-dir=__tests__ || true`,
|
||||
{ encoding: "utf-8" }
|
||||
);
|
||||
expect(result.trim()).toBe("");
|
||||
});
|
||||
|
||||
it("should not use any types in templates.ts function parameters", () => {
|
||||
const result = execSync(
|
||||
`grep -E "\\(d: any\\)|\\(data: any\\)|\\(item: any\\)" "${srcDir}/services/templates.ts" || true`,
|
||||
{ encoding: "utf-8" }
|
||||
);
|
||||
expect(result.trim()).toBe("");
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue