我正在尝试记录请求的 param
对象上的查询字符串类型。我有一个请求 @param 的 Request
类型,但我希望能够覆盖其继承的 param
对象,因为每个请求函数可能有一组不同的查询字符串。
/**
* @typedef {Object} Request
* @property {Object} params - Object that contains parameters passed to a route. (Query strings).
* @property {string} hostname - Hostname from the HTTP-request.
*/
class ProfileController extends Controller {
/**
* Fetch a profile
* @param {Request} req - Request object
* @param {string} req.params.id - Node ID <-- I WANT TO DO THIS, THIS DOESNT WORK
* @param {Object} res - Response
*/
get = (req, res) => {
const { id, hostname } = req.params;
// req.params.id doesn't get intellisense
};
}
最佳答案
你可以这样做:
/**
* @typedef {Object} Request
* @property {Object} params - Object that contains parameters passed to a route. (Query strings).
* @property {string} hostname - Hostname from the HTTP-request.
*/
/**
* @typedef {Object} MyRequest
* @property {Object} params - Object that contains parameters passed to a route. (Query strings).
* @property {string} params.id - Node ID
*/
class ProfileController extends Controller {
/**
* Fetch a profile
* @param {Request & MyRequest} req - Request object
* @param {Object} res - Response
*/
get (req, res) {
const { id, otherParam } = req.params;
}
}
关于javascript - JSDOC:覆盖 typedef 对象属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53554614/