文档过载功能/方法
我一直在尝试使用JSDOC在JS中记录过载功能:
有2个用例:
assignSlave(ticket, userid);
assignSlave(ticket, firstname, lastname);
我想在VSCODE中看起来像这样:
案例1
案例2
等等...
我尝试了 document in JSDOC中的载荷功能 ,但对我不起作用:
/**
* Test
*
* @function assignSlave
* @param {String} ticket
* @param {String} userid
*//**
* Test2
*
* @function assignSlave
* @param {String} ticket
* @param {String} firstname
* @param {String} lastname
*/
function assignSlave(a, b, c){}
assignSlave()
我明白了:
.sstatic.net /
我阅读本文,但不确定在我的情况下它是如何工作的。
I've been trying to document an overload function in JS using JSDoc:
There's 2 use cases:
assignSlave(ticket, userid);
assignSlave(ticket, firstname, lastname);
I'd like to have it look like this in VSCode:
Case 1
Case 2
And so on...
I tried the solution given in Document overloaded function in JSDoc but it didn't work for me:
/**
* Test
*
* @function assignSlave
* @param {String} ticket
* @param {String} userid
*//**
* Test2
*
* @function assignSlave
* @param {String} ticket
* @param {String} firstname
* @param {String} lastname
*/
function assignSlave(a, b, c){}
assignSlave()
I get this:
Is there a way to achieve what I'm trying to do?
I read this article but am not sure how it works in my case.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在Typescript 5中,您可以使用新的
@overload
标签:用于参考: https://devblogs.microsoft.com/typescript/announcing-typescript-5-5-0/#overload-support-support-ipport-in-jsdoc
In TypeScript 5, you can use the new
@overload
tag:For reference: https://devblogs.microsoft.com/typescript/announcing-typescript-5-0/#overload-support-in-jsdoc
像以下片段一样做。从
函数
更改为箭头函数
并相应地设置其类型。最后一件事是为尾随参数分配一个默认值,以便彼此兼容过载类型。这样可以用2个重载来识别功能:
Overload 1
“ https://i.sstatic.net/yn2mql.png” alt =“ Overload 2”>
Do it like the following snippet. Change from
function
to anarrow function
and set its type accordingly. The last thing is to assign a default value to trailing arguments so the overload types are compatible with each other.This way the function is recognized with 2 overloads:
Overload 1
Overload 2