Fez Vrasta
Fez Vrasta

Reputation: 14815

JSdoc use variable as default value

I have a class that takes an options object with a lot of configurations inside.

const DEFAULTS = {
  a: 1,
  b: {
    c: 2,
    d: 3
  }
}

export default class Popper {
  constructor(options) {
    ...

I'm documenting the options properties manually but I'd like to define the default value using the one of the DEFAULTS variable.
Something like the following doesn't work, how can I do?

@param {Object} [options.b=DEFAULTS.b] - The defaults b options

Upvotes: 2

Views: 1278

Answers (1)

jjmerelo
jjmerelo

Reputation: 23477

I don't think jsdoc is prepared to substitute values, template-like. So an option here would be to document the constant, and make a reference to it, like so:

/**
* Default values for options
* @param {number} [ a = 1 ] - this is a
* And so on...
*/
const DEFAULTS = {
  a: 1,
  b: {
    c: 2,
    d: 3
  }
}



export default class Popper {
  /**
  * Popper
  * @param {Object} [options = DEFAULT] See [[DEFAULT]]
  */
  constructor(options) {
    ...

That way the reader can properly be directed to these default values.

Upvotes: 2

Related Questions