Tiddo
Tiddo

Reputation: 6524

JSDoc3 & NodeJS link to types from modules

I try to find how to let JSDoc3 automatically generate links to classes from other modules. I find it hard to explain in words, so let me give some examples. The following script generates the expected output:

/**
 * @constructor
 */
var SomeClass = function(){}

/**
 * @param {SomeClass} someParam description
 */
var someFunc = function(someParam){}

That is, JSDoc3 correctly generates a link from the parameter list of someFunc to the class description of SomeClass. However, when I put SomeClass in an external module I can't seem to let JSDoc3 generate the links:

/**
 * @file SomeClass.js
 * @module SomeClass
 */

/**
 * @constructor
 */
exports.SomeClass(){}


/**
 * @file main.js
 */
var SomeClass = require('./SomeClass');

/**
 * @param {SomeClass} someParam description
 */
function someFunc(someParam){}

Now JSDoc3 correctly generates the documentation for both files, but it doesn't link the parameter type of someFunc to the page of SomeClass. I tried replacing @param {SomeClass} with:

But none of these worked: in all cases the documentation simply shows the text inside the curly brackets (even when I used @link).

How can I let JSDoc3 correctly generate links to the external modules?

Upvotes: 7

Views: 2750

Answers (2)

Tom
Tom

Reputation: 5121

Use typeof import

    /**
     * @param {typeof import("puppeteer").Browser} browser
     */

Docs here

Upvotes: 1

Dan
Dan

Reputation: 151

Use the module: prefix when referencing modules. If the module's return value is the class itself, then use module:SomeClass. If it is a property of the module, use module:SomeClass.SomeClass. The @link tag shouldn't be necessary if jsdoc can find a reference to the existing class documentation.

Upvotes: 5

Related Questions