Goal: eliminate or minimize explicit any casts while keeping runtime behavior unchanged. Tackle in small PRs, running CI=1 npm test and npm run build after each step.
- Centralize shared types: add
src/types.tswithDimensions,BoundingBox,Format,Quality,MaxDimensions; start replacing ad‑hoc shapes in core files. - Define module contracts: add
src/contracts.ts(VersionModule,CalculatorLike,Calculated,InfoDocInput,InfoDoc,CalculatorCtor) and apply insrc/versions.ts,src/transform.ts, andsrc/processor.ts. - Tighten
processor.ts: add explicit fields, type resolvers and options, remove many(this as any)casts, and typeoperations()/infoJson()paths. - Tighten
transform.ts: type calculator/module/format/region and replace broad casts with narrow// @ts-expect-errorwhere Sharp lacks types. - Tighten calculators: type
_canonicalInfo,_parsedInfo,opts.max; aligninfo()withCalculated; reduceanyinsrc/calculator/base.ts. - Type v2/v3 info:
infoDocargs/returns usingInfoDocInput/InfoDoc; keepSet→array conversion typed. - Config guardrails: add
tsconfig.strict.jsonwithnoImplicitAny+strictNullChecksand npm scriptstypecheck/typecheck:strict; later enable@typescript-eslint/no-explicit-anytowarn. - Sweep remaining
anyusages in smaller PRs across files and tests.
Notes
- Prefer
// @ts-expect-error <reason>overanywhere library types are missing (e.g., Sharp TIFF metadata options). - Keep public API types aligned with
types/*.d.ts. Update those once internals are fully typed.