如何在JSDoc中描述结构化对象参数 [英] How to describe destructured object arguments in JSDoc

查看:258
本文介绍了如何在JSDoc中描述结构化对象参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个将对象作为参数的JavaScript函数,则可以使用JSDoc描述对象的预期属性,如下所示:

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

如果我使用ECMAScript 6解构定义函数而不完全给真实的参数对象起一个名字,该如何描述这些属性?

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;

推荐答案

事实证明JSDoc确实通过构成占位符名称来支持销毁.它缺少官方文档.

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;

这篇关于如何在JSDoc中描述结构化对象参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆