Elevista
Elevista

Reputation: 31

How to indicate multiple types param with repeatable parameter?

/**
 * Returns the sum of all numbers passed to the function.
 * @example
 * sum([1,2,3])
 * //returns 6
 * sum(1,2,3)
 * //returns 6
 * @param {number[]|...number} params - ???
 */
function sum(params) {
    var args = params instanceof Array ? params : arguments;
    for (var i = 0, sum = 0; i < args.length; i++)
        sum += args[i];
    return sum;
}

'params' can be a array or repeatable numbers

but "@param {number[]|...number}" not working.

Written document output have no difference with "@param {number[]|number}"

Which is the best way to indicate on this situation?

Upvotes: 2

Views: 1244

Answers (1)

benbotto
benbotto

Reputation: 2439

The trick is using parenthesis. I used the following at it works.

* @param {...(object|string)} col - An optional set of columns to select.

Updated for your parameter names, this should work:

* @param {...(number[]|number)} params - ???

I can't find any documentation for the parenthesis, but under JSDoc 3.4.2 that does the trick.

This comment:

/**
 * Select columns manually.
 * @param {...(object|string)} col - An optional set of columns to select.
 * Each argument can either be a fully-qualified column name in the form
 * &lt;table-alias&gt;.&lt;column-name&gt;, or an object with the following
 * properties below.  If no columns are specified, then all columns are
 * selected.
 * @param {string} col.column - The fully-qualified column name.
 * @param {string} col.mapTo - The name of the property that the column
 * should be mapped to in the resulting normalized object.  @param
 * @param {function} col.convert - A converter function that takes a single value
 * from the database and transforms it.  For example, a function that
 * converts a bit from the database to a boolean value.
 * @return {this}
 */

Yields this documentation:

enter image description here

Hope that helps!

Upvotes: 1

Related Questions