I combine other answer in How to annotate Express middlewares with JSDoc? 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.
other methods/properties defined on express.Request
, for example req.headers

req.body
hint

req.query
hint
