跨多个方法记录相同的jsduck配置类型

Documenting the same jsduck config type across multiple methods

本文关键字:jsduck 配置 置类型 方法 记录      更新时间:2023-09-26

两个问题:

首先,有人知道如何继承一些文档的一部分吗?特别针对"options"对象:

 * @param {Object}          opts
 * @param {String}          opts.effect    Transition effect.  fade|slide
 * @param {String}          opts.direction Direction to do the transition, when applicable.  up|down|left|right
 * @param {String|Number}   opts.duration  Transition duration in ms, or one of short|long
 * @param {String|Function} opts.timing    Transition timing function, or one of

基本上,我希望文档在多个方法中,但我不想把它复制到每个方法中,我想要一个公共的地方来修改它。

第二,如果我能以某种方式继承文档,我能扩展它吗?例:我想:
method foo:
    opts.opt-a // inherited
    opts.opt-b // inherited
    opts.opt-c // inherited
    opts.opt-d // local to this method

不支持这种继承。

你可以做的是,将这个options对象记录为一个文档类:

/**
 * @class FooOpts
 * A configuration object for Foo, instantiated with object literal.
 */
/** @cfg {String} effect */
/** @cfg {String} direction */
/** @cfg {String|Number} duration */
/** @cfg {String|Function} timing */

然后使用这个document -only-class作为参数类型:

* @param {FooOpts} opts Config object for the FooOpts class.

要覆盖这些选项,可以定义一个子类。

根据您拥有的选项的数量,这种方法的开销可能不合理。但是,如果您在几个地方指定了相同的选项,这可能表明您最好为它们创建一个实际的具体类。