How to reference a @class in another file with JSdoc?
Asked Answered
O

1

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?

Octarchy answered 19/10, 2016 at 9:8 Comment(0)
S
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){}
Starspangled answered 19/10, 2016 at 9:19 Comment(4)
that references instances of Bar, not Bar the constructorOctarchy
jsdoc documentation is so obscure. how do i avoid writing @param's twice?Octarchy
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: usejsdoc.org/tags-member.html !Starspangled
yes, but i'm referencing a class/function/anything that is already defined somewhere else. though it seems @alias is what i needOctarchy

© 2022 - 2024 — McMap. All rights reserved.