JSDOC:覆盖typedef对象属性

时间:2018-11-30 09:24:23

标签: javascript jsdoc

我正在尝试在请求的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
   };
 }

1 个答案:

答案 0 :(得分:1)

您可以这样做:

/**
 * @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;
  }
}