JSDoc 中的文档重载函数

Sha*_*mal 8 javascript jsdoc

我有一个重载的切换函数,并且想要使用 JSDoc 记录行为。

如果定义了该值,则窗口状态将设置为 true 参数的布尔值,如果未定义,则窗口状态会切换。我正在寻找这样的东西。

/**
 * Set the map window in mobile
 * @param {undefined|*} on - toggle or set the window state
 *  - {undefined} toggles window state
 *  - {*} set window state
 */
toggleWindow(on) {
  if (on === undefined) {
    on = !this.state.window;
  }
  this.setState({ mapWindow: !!on });
}
Run Code Online (Sandbox Code Playgroud)

Kir*_*use 4

取自这里

您需要将每个评论的开头和结尾放在一起,如下所示:

/**
 * DateRange class to store ranges and query dates.
 *
 * @constructor
 * @param {(Moment|Date)} start Start of interval
 * @param {(Moment|Date)} end End of interval
 *//**
 * DateRange class to store ranges and query dates.
 *
 * @constructor
 * @param {!Array} range Array containing start and end dates.
 *//**
 * DateRange class to store ranges and query dates.
 *
 * @constructor
 * @param {!String} range String formatted as an IS0 8601 time interval
 */
function DateRange(start, end) {
  // ...
}
Run Code Online (Sandbox Code Playgroud)

但请注意,构造函数重载并不组合在一起。每个重载仍然会收到完整的成员列表,因此部分文档变得多余。不过,可能可以在模板中修复。

  • 我认为这仅对构造函数有效,对函数无效。[这个答案](/sf/answers/5135979971/)对我有用。我还必须在函数定义处添加类型忽略(但不在使用点处)。 (2认同)