JSDOC:覆盖typedef对象属性

3
我正在尝试记录请求的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个回答

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;
  }
}

5
谢谢,但我在req.params.id上没有获得智能感知,有可能以某种方式获得吗? - Jesper Johansson

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接