首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在一些参数被解构而其他参数没有被解构的情况下记录函数的参数(JSDoc)

如何在一些参数被解构而其他参数没有被解构的情况下记录函数的参数(JSDoc)
EN

Stack Overflow用户
提问于 2021-09-06 07:20:18
回答 1查看 58关注 0票数 0

How to document deconstructed parameters with JsDoc解释了如果只有一个正被解构的参数,如何记录参数。

我使用此class创建自定义事件:

代码语言:javascript
运行
复制
const EVENT_CONFIG_DEFAULTS = Object.freeze({
    bubbles: true,
    composed: true,
});
/**
 * class for all FW custom events
 */
export class FWEvent extends CustomEvent {
    #sourceEvent = null;
    #sourceElement = null;
    /**
     *
     * @param {string} name name of the event, see fw-events.js
     * @param {EventInit} eventInit event configuration
     * @param {Event} [sourceEvent] optional source event
     * @param {HTMLElement} [sourceElement] optional source element to circumvent event retargeting
     */
    constructor(name, eventInit, { sourceEvent, sourceElement }) {
        super(name, { ...EVENT_CONFIG_DEFAULTS, ...eventInit });

        this.#sourceEvent = sourceEvent || null;
        this.#sourceElement = sourceElement || null;
    }

    get sourceEvent() {
        return this.#sourceEvent;
    }

    get sourceElement() {
        return this.#sourceElement;
    }
}

因此,我有一个可选的第三个参数,由于解构方面的限制,我无法命名该参数。

我如何正确地记录这一点?显示的JSDoc显然是不正确的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-07 08:32:08

记录它们的方式与记录嵌套属性的方式相同:

代码语言:javascript
运行
复制
/**
 * @param {boolean} x
 * @param {boolean} y
 * @param {Object} [stuff]
 * @param {string} [stuff.bar]
 * @param {string} [stuff.baz]
 */
function foo(x, y, {bar, baz}) {

}

以下是我将鼠标悬停在foo上时VS Code IntelliSense显示的工具提示的屏幕截图

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69070606

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档