Skip to content

Add JSDoc type annotations and .d.ts files for route handlers#1453

Open
JamieMagee wants to merge 1 commit intomasterfrom
add-jsdoc-types-to-routes
Open

Add JSDoc type annotations and .d.ts files for route handlers#1453
JamieMagee wants to merge 1 commit intomasterfrom
add-jsdoc-types-to-routes

Conversation

@JamieMagee
Copy link
Contributor

Summary

  • Add JSDoc @param/@typedef annotations to all route handler functions and companion .d.ts declaration files so TypeScript consumers get type info.
  • Add a tsconfig.json for JS type-checking configuration.
  • Widen the AsyncMiddlewareFunction return type from Promise<void> to Promise<any> to match actual usage (handlers return response.send(...) which yields Response).

JS behavior changes

These are small and shouldn't affect production HTTP behavior, but are worth calling out:

routes/definitions-1.0.0.js — The force query param check dropped the === true (boolean) comparison, keeping only === 'true' (string). Express query values are always strings, so the boolean branch was dead code in normal requests. If any test or middleware sets the value as an actual boolean, that path would stop matching.

routes/definitions.js — Same treatment for matchCasing (dropped === false). Also removed the Array.isArray guard around request.get('User-Agent') since Express always returns a single string for that header. Caught errors are now cast to Error before accessing .message.

routes/webhook.jsreturn info(request, response, ...) was split into info(...); return. Functionally equivalent today, but slightly more fragile to future edits since removing the return would cause a double-response. The unused request parameter in info() was renamed to _request.

Annotate route handler functions with JSDoc @param/@typedef tags
for Request/Response types, and add companion .d.ts declaration
files so downstream TypeScript consumers get type info.

A few minor JS changes came along with the annotations:

- definitions-1.0.0: drop redundant boolean check on req.query.force
  (Express query values are always strings)
- definitions: same for matchCasing, remove unnecessary Array.isArray
  guard on User-Agent header, cast caught errors before accessing
  .message
- webhook: rename caught exception variable, split 'return info()'
  calls into separate info()/return statements, prefix unused
  'request' param with underscore

Also adds a tsconfig.json for the JS checking configuration.
@JamieMagee JamieMagee force-pushed the add-jsdoc-types-to-routes branch from 14a9764 to 0e91d22 Compare February 11, 2026 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant