Skip to content

Convert type-checked lib .js files to .ts #61

Description

@dalberola

Summary

Finish the type-safety track started in #28 by converting the remaining // @ts-check-annotated .js files in packages/dredd/lib to real .ts, replacing JSDoc type annotations with native TypeScript signatures.

Why now

  • [P1] Incrementally type-check packages/dredd/lib (.js → typed) #28 (// @ts-check every lib file) is complete — 38/39 files are checked under strict (only lib/index.js is deferred to the ESM work in [P2] Migrate packages from CommonJS to ESM #29).
  • lib/ is already mixed: 22 .ts + 39 .js. The toolchain handles it today — tsconfig is allowJs + node16 + strict, tests run via ts-node, and the recently-added lib/validation/ module (8 .ts files) built, tested, and shipped cleanly. No tooling changes are needed.
  • With type-checking already done, conversion is largely mechanical: JSDoc @param {T} / @returns → real signatures, tightening any along the way. The hard part (making the code type-check) is behind us.

Scope

  • Rename each // @ts-check lib/**/*.js.ts and replace JSDoc types with native TS.
  • One file (or one cohesive cluster) per PR, mirroring the [P1] Incrementally type-check packages/dredd/lib (.js → typed) #28 cadence.
  • No behaviour changes and no change to the published surface: the package stays CommonJS (main: build/index.js, no "type": "module"); tsc emits CommonJS regardless of source extension, so consumers are unaffected.

Out of scope

Suggested order (bottom-up: foundation & leaves first)

Converting high-fan-in foundation modules first means their types immediately benefit every importer as those get converted. Grounded in current lib fan-in:

  1. Logging cluster (highest leverage, self-contained, tiny): createConsoleLogger.jslogger.js (imported by 19 files) → reporters/reporterOutputLogger.js (10). Already grouped this way in [P1] Incrementally type-check packages/dredd/lib (.js → typed) #28.
  2. Shared leaves (zero internal deps, trivial): expandTilde.js, which.js, ignorePipeErrors.js, getGoBinary.js, getProxySettings.js, hooksLog.js, compileTransactionName.js, prettifyResponse.js.
  3. Self-contained mid-size: httpClient.js, readLocation.js, performRequest.js, configUtils.js, annotationToLoggerInfo.js.
  4. Configuration cluster: configuration/{validateConfig,normalizeConfig,getProxySettings,applyLoggingOptions,applyConfiguration,index}.js.
  5. Reporters: reporters/{BaseReporter,DotReporter,CLIReporter,…}.js then configureReporters.js.
  6. Hubs last (high internal fan-out → most any leakage until neighbours are typed): Hooks.js, addHooks.js, HooksWorkerClient.js, init.js, Dredd.js, CLI.js, TransactionRunner.js.
  7. index.js — last, with [P2] Migrate packages from CommonJS to ESM #29.

Acceptance criteria

  • Every lib/**/*.js except index.js is converted to .ts with native types (no remaining // @ts-check pragmas in lib).
  • tsc --build passes under strict; yarn lint, yarn test, smoke all green per PR.
  • Published package remains CommonJS; no consumer-visible change.

Follow-on to #28. Interacts with #29 only for index.js.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions