How to describe destructured object arguments in JSDoc

我是研究僧i 提交于 2019-12-04 12:10:06

问题


If I have a JavaScript function taking an object as a parameter, I can describe expected properties of the object with JSDoc like this:

/**
 * @param bar
 * @param bar.baz {number}
 * @param bar.qux {number}
 */
function foo(bar) {
    return bar.baz + bar.qux;
}

How do I describe these properties if I define my function with ECMAScript 6 destructuring, not giving the real parameter object a name at all?

const foo = ({ baz, qux }) => baz + qux;

回答1:


It turns out JSDoc does support destructing via making up a placeholder name. It is lacking in official documentation.

http://usejsdoc.org/tags-param.html#parameters-with-properties

/**
 * @param {Object} param - this is object param
 * @param {number} param.baz - this is property param
 * @param {number} param.qux - this is property param
 */
const foo = ({ baz, qux }) => baz + qux;



回答2:


I had the same question too. Now I am using Visual Code Studi, its plugin does something like this (this is suitable for me):

/**
 * @param  {} {a
 * @param  {} b
 * @param  {} c}
 * @param  {} {d}
 */
const aaa = ({a,b,c},{d}) => {

}


来源:https://stackoverflow.com/questions/44644750/how-to-describe-destructured-object-arguments-in-jsdoc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!