SumNeuron
SumNeuron

Reputation: 5188

JSDoc: reference @param of method in another @param

I am new to using JSDocs and couldn't find an answer to this question.

Suppose I wanted to write this simple function:

function hasQ(array, item) {return array.includes(item);}

which with JSDoc's I would mark-up like:

/**
* Another way to call array.includes(item);
* @param {Array} array
* @param {*} item to test if contained in array
* @returns
*/

Is there a way for me to markup the word array in the second @param statement such that it references the first @param?

This is just a toy example, but I hope it makes the concept clear.

Upvotes: 17

Views: 12441

Answers (4)

Ram
Ram

Reputation: 611

JSDoc has been updated recently. Now you can cross-reference parameter by using {@link YOUR_PARAMETER}. Your example can be updated as:

/**
* Another way to call array.includes(item);
* @param {Array} array
* @param {*} item to test if contained in {@link array}
* @returns
*/

You can read more about it here : JSDoc Inline Link

Upvotes: 3

Babak
Babak

Reputation: 1344

Cross-Reference Parameters

Regarding @param as far as I know, there's no way to cross-reference parameters. As suggested here you can use plain English.

As a partial solution, you can use markdown's backticks to highlight the param name (as described here), for example:

/**
 * @param {*} item to test if contained in `array`
 */

Sidenote: Reference External

There's a concept of inline @link to external resources in JSDoc that I guess would be useful here. You can make it clear in your description that for example your talking about the function includes of Array:

/**
* Another way to call [Array's includes function]{@link external:Array#includes}
* @param {Array} array
* @param {*} item to test if contained in array
* @returns
*/
function hasQ(array, item) {
    return array.includes(item);
}

Or if you prefer a link without a text, just remove the part inside [] in the first line:

/**
 * Another way to call {@link external:Array#includes}
 */

Read More

In case you're interested to read more:

Upvotes: 9

Hernán Pentimalli
Hernán Pentimalli

Reputation: 490

There is no way to do that. Source: https://github.com/jsdoc/jsdoc/issues/1145

Upvotes: 2

Valera Checha
Valera Checha

Reputation: 294

I did not see the possibility of writing related parameters (but see parameters with properties). But you can write description ;)

/**
 * @method
 * @param {Array} array - description for this param
 * @param {*} item - description for this param
 * @description Please write your description for Method
 * @returns {*|boolean}
 */
const hasQ = (array, item) => array.includes(item);

Upvotes: -2

Related Questions