JSDoc @param - reference class from another module

Viewed 1726

I have 2 Node modules. In module A I have the following definition:

/**
 * HTTP Client
 * @module src/http/client
 */
/**
 * A HTTP Client
 * @alias src/http/client
 */
class HTTPClient {
   [... class def with documented methods etc]
}
module.exports = HTTPClient

And now in module B I want to say that the first constructor parameter should be of type HTTPClient. So I tried the following

class PackageFactory {
    /**
     * @param {module:src/http/client} httpClient - the HTTPClient instance
     */
    constructor(httpClient) {
       this._httpClient = httpClient
    }
}

I also tried a few variations but it never worked. Within module B the httpClient is always of type "any". What do I have to change so I can see the class member of HTTPClient in module B?

1 Answers

The solution was easier then I thought. There is no need to include the module paths (aka longname) or anything.

const HTTPClient = require('../http/client')
class PackageFactory {
    /**
     * @param {HTTPClient} httpClient - the HTTPClient instance that shall be used to make requests
     */
    constructor(httpClient) {
       this._httpClient = httpClient
    }
}
Related