Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 569
Wes Avatar asked Oct 19 '16 09:10

Wes


People also ask

Can you use JSDoc with TypeScript?

You can use most JSDoc type syntax and any TypeScript syntax, from the most basic like string to the most advanced, like conditional types.

What is a Namepath?

When referring to a JavaScript variable that is elsewhere in your documentation, you must provide a unique identifier that maps to that variable. A namepath provides a way to do so and disambiguate between instance members, static members and inner variables.

What is a JSDoc comment?

JSDoc is a markup language used to annotate JavaScript source code files. Using comments containing JSDoc, programmers can add documentation describing the application programming interface of the code they're creating.


1 Answers

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){}
like image 143
Axel Isouard Avatar answered Sep 26 '22 16:09

Axel Isouard