VSCode没有在对象中显示正确的参数

时间:2017-03-18 20:07:08

标签: visual-studio-code jsdoc

我有像这样的jsdoc我的功能:

/**
 * @typedef {Object} SearchTerms
 * @property {string} what
 * @property {string} where
 * @property {boolean} online
 */

/**
 * From react-router params, which are URL encoded, it figures out the "what", "where", and "online" terms.
 *
 * @export
 * @param {Object} params The `params` field from react-router component props.
 * @param {string} [params.what="Everything"] The subject of users search.
 * @param {string} [params.where] The location of users search.
 * @returns {SearchTerms}
 */
export function getSearchTerms(params)  {

但是,在悬停函数时,params键未正确展开:

是否有适当的扩展params参数?我希望它能显示出来:

除了它还应该显示带问号的可选项。当我输入参数时,它应该像这样显示该参数的描述:

1 个答案:

答案 0 :(得分:1)

问题是您已将params参数的类型指定为Object。你应该把你的参数作为第二个@typedef

/**
 * @typedef SearchOptions
 * @property {String} [what="Everything"] The thing
 * @property {String} [where] A place
 */

/**
 * @param {SearchOptions} params
 */
function getSearchTerms(params){ ... }

使用这样的命名界面,VSCode应该像你正在寻找的那样在Intellisense中显示参数。

相关问题