JSDOC承诺多种解决类型

发布于 2025-01-21 15:48:16 字数 1144 浏览 2 评论 0原文

我保证我试图使用JSDOC进行记录。它具有三种解析类型,string []object []对象。似乎有多种建议记录这一点的方法,但我似乎找不到任何具体的东西。

httpps://github.com/jsdoc/jsdoc/jsdoc/jsdoc/1197#issuecomment/197#issuecomment-1197#issuecomment- 312948746 似乎很喜欢这样的东西:

/**
 * The results of the DNS resolution request
 * @promise DNSResolve
 * @fufill {(string[]|Object[]|Object)}
 * @reject {Error}
 */

/**
 * Resolve a DNS record
 *
 * @returns {DNSResolve} The result
 */

注意:在此中,我正在使用多种类型的答案,如下所示您如何使用混合参数类型记录JSDOC?

但是,这似乎并未实现,并且没有出现在 https://jsdoc.app/ 。它似乎也很肿又缠绕。

我的想法是遵循打字稿返回类型的想法,

Promise<string[] | Object[] | Object>

是否有关于如何执行此操作的任何标准,或者我应该只使用第1197号问题建议的方案

I have a promise that I am trying to document using JSDoc. It has three resolve types, string[], Object[] and Object. There seems to be a number of ways suggested to document this but I can't seem to find anything concrete.

https://github.com/jsdoc/jsdoc/issues/1197#issuecomment-312948746 would seem to sugest something like this:

/**
 * The results of the DNS resolution request
 * @promise DNSResolve
 * @fufill {(string[]|Object[]|Object)}
 * @reject {Error}
 */

/**
 * Resolve a DNS record
 *
 * @returns {DNSResolve} The result
 */

Note: In this one I am using the answer to multiple types as suggested here How do you document JSDoc with mixed parameter type?

However, this doesn't seem to have been implemented and doesn't appear on https://jsdoc.app/. It also seems very bloated and long winded.

My idea was to follow TypeScripts return type idea of

Promise<string[] | Object[] | Object>

Is there any kind of standard on how to do this or should I just use the scheme suggested by issue #1197

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

熟人话多 2025-01-28 15:48:16

您链接的线程具有您需要的所有答案。如果您发现第一种方法太长,请使用短手承诺返回类型:

/**
 * @returns {Promise<(string[]|object[]|object>}
 */

但是,这似乎并未实现,也没有出现在

似乎也很肿又缠绕。

那是因为jsdoc.app非常非常过时。我也注意到了这一点,因为许多较新的短手jsdoc速记语法对于许多事情并不是最新的,但是在IDE的vscode和webstorm中都可以正常工作。

例如,@typedef文档不提及/** @typedef {{id:number,name:string}}&nbsp;*/

它似乎是“肿”的,因为它是完整的表单版本,如果您需要在其所有零件中添加描述,或者需要记录拒绝类型(短手版本不支持),则非常适合。如果您不需要,那么短手版本就是您应该使用的。

另外,请记住 https://jsdoc.app/ 由同一存储库/开发人员维护为 https://github.com/jsdoc/jsdoc ,与您链接的问题相同。因此,在该问题线程上所说的任何话都应被视为真理。

是否有关于如何执行此操作的任何标准,还是我应该使用问题#1197

建议的方案

短手和完整的语法都应被视为标准标准,并且都不比其他方案更好。使用适合您需求的哪个。合适的工作的正确工具。

The thread you linked has all the answers you need. If you find the first approach too long-winded, use the short hand promise return type:

/**
 * @returns {Promise<(string[]|object[]|object>}
 */

However, this doesn't seem to have been implemented and doesn't appear on https://jsdoc.app/. It also seems very bloated and long winded.

That's because jsdoc.app is very, very out of date. I've noticed this too, as a lot of newer short-hand JSDoc shorthand syntax for a lot of things aren't up to date on the site but work fine in IDE's like VSCode and Webstorm.

For example, the @typedef docs don't mention there's a shorthand version like /** @typedef {{ id: number, name: string }} */

It seems "bloated" because it's the full form version which is well suited if you need to add a description to all its parts, or if you need to document reject types (which the short hand version doesn't support). If you don't need that, the short hand version is what you should use.

Also, keep in mind https://jsdoc.app/ is maintained by the same repository/developer as https://github.com/jsdoc/jsdoc , the same repo from the issue you linked. So anything said on that issue thread should be considered as truth.

Is there any kind of standard on how to do this or should I just use the scheme suggested by issue #1197

Both the short hand and full syntax should be considered standard, and neither is better than the other. Use whichever fits your needs. Right tool for the right job.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文