6

E.g. MyClass.js

/**
 * @class
 * @name module:Bar
 * @param {number} a1
 * @param {string} a2
 */
function Bar(a1, a2){}

And, in another file:

/** @type module:Bar.constructor */ // made up syntax
var Bar = require("./MyClass.js");

Re-defining @class works but it's not convenient:

/**
 * @class
 * @name module:Bar
 * @param {number} a1
 * @param {string} a2
 */
var Bar = require("./MyClass.js");

How do I do it?

Wes
  • 3,978
  • 4
  • 24
  • 45

1 Answers1

5

The class name alone should be enough.

/**
 * @type module:Bar
 */
var Bar = require("./MyClass.js");

You should use @alias instead of @name:

Warning: By using the @name tag, you are telling JSDoc to ignore the surrounding code and treat your documentation comment in isolation. In many cases, it is best to use the @alias tag instead, which changes a symbol's name in the documentation but preserves other information about the symbol.

/**
 * @class
 * @alias module:Bar
 * @param {number} a1
 * @param {string} a2
 */
function Bar(a1, a2){}
Axel Isouard
  • 1,498
  • 1
  • 24
  • 38
  • that references instances of Bar, not Bar the constructor – Wes Oct 19 '16 at 09:20
  • 2
    jsdoc documentation is so obscure. how do i avoid writing @param's twice? – Wes Oct 19 '16 at 09:49
  • There's no other way to do so. You need to type one line for each parameter, it's the same rule for class members: http://usejsdoc.org/tags-member.html ! – Axel Isouard Oct 19 '16 at 09:52
  • yes, but i'm referencing a class/function/anything that is already defined somewhere else. though it seems @alias is what i need – Wes Oct 19 '16 at 10:52