Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Document overloaded function in JSDoc

I have an overloaded toggle function and want to document the behaviors w/ JSDoc.

If the value is defined the window state is set to the boolean value of the truthy parameter, if undefined the window state toggles. I'm looking for something like this.

/**
 * 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 });
}
like image 386
Shanimal Avatar asked Apr 29 '26 22:04

Shanimal


1 Answers

Taken from here:

You need to nestle the start and end of each comment together like so:

/**
 * 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) {
  // ...
}

Note, however, that constructor overloads are not grouped together. Each overload still receives the full member list, such that part of the documentation becomes redundant. Might be fixable in the template, however.

like image 56
Kiruse Avatar answered May 01 '26 12:05

Kiruse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!