Add JSDoc type annotations and .d.ts files for route handlers#1453
Open
JamieMagee wants to merge 1 commit intomasterfrom
Open
Add JSDoc type annotations and .d.ts files for route handlers#1453JamieMagee wants to merge 1 commit intomasterfrom
JamieMagee wants to merge 1 commit intomasterfrom
Conversation
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.
14a9764 to
0e91d22
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@param/@typedefannotations to all route handler functions and companion.d.tsdeclaration files so TypeScript consumers get type info.tsconfig.jsonfor JS type-checking configuration.AsyncMiddlewareFunctionreturn type fromPromise<void>toPromise<any>to match actual usage (handlers returnresponse.send(...)which yieldsResponse).JS behavior changes
These are small and shouldn't affect production HTTP behavior, but are worth calling out:
routes/definitions-1.0.0.js— Theforcequery 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 formatchCasing(dropped=== false). Also removed theArray.isArrayguard aroundrequest.get('User-Agent')since Express always returns a single string for that header. Caught errors are now cast toErrorbefore accessing.message.routes/webhook.js—return info(request, response, ...)was split intoinfo(...); return. Functionally equivalent today, but slightly more fragile to future edits since removing thereturnwould cause a double-response. The unusedrequestparameter ininfo()was renamed to_request.