如何使用 JSdoc 在另一个文件中引用 @class?

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

例如MyClass.js

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

并且,在另一个文件中:

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

重新定义 @class 可以,但不方便:

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

我该怎么做?

单凭 class 名称就足够了。

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

你应该使用 @alias 而不是 @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){}