我有2个Node模块。在模块A中,我有以下定义:
/**
* HTTP Client
* @module src/http/client
*/
/**
* A HTTP Client
* @alias src/http/client
*/
class HTTPClient {
[... class def with documented methods etc]
}
module.exports = HTTPClient
现在在模块B中,我想说第一个构造函数参数应该是HTTPClient类型。所以我尝试了以下
class PackageFactory {
/**
* @param {module:src/http/client} httpClient - the HTTPClient instance
*/
constructor(httpClient) {
this._httpClient = httpClient
}
}
我也尝试了一些变化,但它从未奏效。在模块B中,httpClient总是类型为#34;任何"。我需要更改什么才能在模块B中看到HTTPClient的类成员?
答案 0 :(得分:2)
我认为解决方案更容易。不需要包含模块路径(也就是长名称)或任何东西。
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
}
}