admin管理员组文章数量:1296495
I want to document a function written in another module, which uses http.ClientRequest typed parameter. I want something like this, but it does not work:
/**
* @param {ClientRequest} req
*/
function setToken(req) {
}
I have tried also @param {http.ClientRequest}
, but it did not work.
Update:
Basically I solved that problem by importing the required module by import http from "http";
. However, I don't want to import it because this module does not use http module
but provides helper functions.
I want to document a function written in another module, which uses http.ClientRequest typed parameter. I want something like this, but it does not work:
/**
* @param {ClientRequest} req
*/
function setToken(req) {
}
I have tried also @param {http.ClientRequest}
, but it did not work.
Update:
Basically I solved that problem by importing the required module by import http from "http";
. However, I don't want to import it because this module does not use http module
but provides helper functions.
3 Answers
Reset to default 7After improve answer from IGx89 I got a shorter variant without typedef. I prefer this variant when I reference to another module one time:
/**
* @param {import('http').ClientRequest} req
*/
function setToken(req) {
}
But if you need reference to some type from another module with long path variant with typedef looks shorter.
Add the following to the top of your file:
/** @typedef {import('http').ClientRequest} ClientRequest */
I had this same problem myself (though regarding a module in my own app) and also had a very hard time finding the solution. I eventually figured out the above syntax by reading through this issue in the TypeScript GitHub repo: https://github./Microsoft/TypeScript/issues/14377
It does not work because it is a custom type JSDoc don't know. You have to setup your own definition with a @typedef.
/**
* A number, or a string containing a number.
* @typedef {(number|string)} NumberLike
*/
/**
* Set the magic number.
* @param {NumberLike} x - The magic number.
*/
function setMagicNumber(x) {
}
See the full examples on JSDoc typedef tag definition examples
I made an example which worked for me with JSDoc 3.5.3
/** @typedef {ClientRequest} TestReq */
/**
* @param {TestReq} req
*/
function setToken(req) {
}
JSDoc output image
本文标签: javascriptJSDoc in VS code for documenting function with module39s typeStack Overflow
版权声明:本文标题:javascript - JSDoc in VS code for documenting function with module's type - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741604453a2387891.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论