JSDoc3 & NodeJS refers to types from modules

I am trying to find how to enable JSDoc3 to automatically generate class references from other modules. It’s hard for me to explain in words, so let me give you a few examples. The following script generates the expected result:

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

That is, JSDoc3 correctly generates a link from the list of someFunc parameters to describe the SomeClass class. However, when I put SomeClass in an external module, I cannot get JSDoc3 to generate 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 creates documentation for both files, but does not bind the parameter type someFunc to the SomeClass page. I tried replacing @param {SomeClass} with:

  • @param {SomeClass.SomeClass}
  • @param {SomeClass/SomeClass}
  • @param {@link SomeClass}
  • @param {@link SomeClass.SomeClass}
  • @param {@link SomeClass/SomeClass}

But none of them worked: in all cases the documentation just shows the text inside the curly braces (even when I used @link).

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

+4
source share
1 answer

Use the module: prefix when accessing modules. If the return value of the module is the class itself, use module:SomeClass . If this is a module property, use module:SomeClass.SomeClass . The @link tag should not be necessary if jsdoc can find a link to existing class documentation.

+4
source

Source: https://habr.com/ru/post/1440006/


All Articles