Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 329
SumNeuron Avatar asked May 14 '18 11:05

SumNeuron


2 Answers

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

like image 38
Hernán Pentimalli Avatar answered Nov 16 '22 03:11

Hernán Pentimalli


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:

  • @external tag
  • inline @link tag
  • @see tag
like image 112
Babak Avatar answered Nov 16 '22 03:11

Babak