How to document deconstructed parameters with JsDoc解释了如果只有一个正被解构的参数,如何记录参数。
我使用此class创建自定义事件:
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显然是不正确的。
发布于 2021-09-07 08:32:08
记录它们的方式与记录嵌套属性的方式相同:
/**
* @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显示的工具提示的屏幕截图

https://stackoverflow.com/questions/69070606
复制相似问题