How can I add JSDoc comments inside functions?

213 Views Asked by At

How can I add valid JSDoc comments inside functions? Is there a jsconfig.json setting I can use? E.g.

// Doesn't work inside vscode
function arrayMove(index) {
  /**
   * @param {Number} index
   * @return {Array}
   */
  // ...
}

instead of

// Works inside vscode
/**
 * @param {Number} index
 * @return {Array}
 */
function arrayMove(index) {
  // ...
}
1

There are 1 best solutions below

0
starball On

As far as I know, there's no VS Code setting that makes it understand JSDoc comments inside functions rather than outside-and-before them. (From doing a simple search of VS Code's settings which include "jsdoc" in their names).

And from JSDoc's intro docs, I'm getting the impression that that wouldn't be valid JSDoc anyway:

JSDoc comments should generally be placed immediately before the code being documented.

From a quick skim of JSDoc's configuration docs and commandline argument docs, I didn't see anything that looked like such a setting at the JSDoc level either (if something's not supported/valid in JSDoc, I wouldn't expect it to be supported/valid VS Code's JSDoc IntelliSense either).

I'm guessing you're coming from Python? I say just get used to it.