[2021-03-02 Update] Original answer is like 100% JSDOC + 0% typescript, but I found a 20% JSDOC + 80% typescript (pure definition) solution. In typescript github, it mentioned this method. See the final paragraph in post.
I combine other answer and modify some code,
it could include all of the methods/properties defined on express.Request
and event custom request body.
It could not only use in request.body
, but also support in req.query
.
That because express.Request
support generics, so we could use this in JSDoc.
First, remember to install @types/express
with npm install --save-dev @types/express
.
Second, setup like following code.
// @ts-check
/**
* @typedef {object} showRequestBody
* @property {string} name this is name in request body
* @property {number} age this is age in request body
*
* @typedef {object} showRequestQuery
* @property {string} name this is name in query
* @property {number} age this is age in query
*
* @param {import('express').Request<{}, {}, showRequestBody, showRequestQuery>} req
* @param {import('express').Response} res
* @param {import('express').NextFunction} next
*/
exports.show = function(req, res, next) {
};
Note: I use it in vscode.
I leave answer here, and I hope this will help other people also have this question.
other methods/properties defined on express.Request
, for example req.headers

req.body
hint

req.query
hint

20% JSDOC + 80% typescript
The following example doesn't need tsconfig.json
or install extra tsc
.
But, you couldn't use jsdoc to generate documentation.
With import + export definition
If you want to extend interface with importing some module, you need to use export in definition. Then import it in JSDOC.


Without import + export definition
If you don't want to import custom definition in JSDOC, you could just define the interface without import and export. Then, you could directly use it in JSDOC.


Extend the express module
There is another way to build custom interface, just use declare module to extend the interface. You could even define custom method.


