JsDoc中如何返回void?

发布于 2024-10-13 08:56:25 字数 154 浏览 4 评论 0原文

JsDoc中是否有指定的方法或函数声明返回void?目前我认为 void 是默认返回值,其他返回值必须特别提供:

/**
 * @return {Integer} The identifier for ...
 */

Is there a specified way to declare a method or a function to return void in JsDoc? Currently I am in the belief that void is the default return value, and other return values must be specifically provided:

/**
 * @return {Integer} The identifier for ...
 */

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

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

发布评论

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

评论(5

悟红尘 2024-10-20 08:56:25

Closure Compiler

根据 Google Closure Compiler 的文档,如果没有返回任何内容,则应省略 @return 注释。

如果没有返回值,请勿使用@return标签。

来源: https://developers. google.com/closure/compiler/docs/js-for-compiler#tags

jsdoc-toolkit

但是,进一步的文档还指出 returnType 和 returnDescription 是可选参数。

returnType - 可选:返回值的类型。

returnDescription - 可选:任何附加描述。

来源: https://code.google.com/ p/jsdoc-toolkit/wiki/TagReturns

摘要

您可以省略返回注释,也可以将其包含在不带任何参数的情况下。

Closure Compiler

According to the documentation of Google's Closure Compiler if nothing is being returned, the @return annotation should be omitted.

If there is no return value, do not use a @return tag.

Source: https://developers.google.com/closure/compiler/docs/js-for-compiler#tags

jsdoc-toolkit

However further documentation also states that the returnType and returnDescription are optional parameters.

returnType - Optional: the type of the return value.

returnDescription - Optional: any additional description.

Source: https://code.google.com/p/jsdoc-toolkit/wiki/TagReturns

Summary

You could either leave out the return annotation or include it without any parameters.

神妖 2024-10-20 08:56:25

我不相信您必须从 JsDoc 中的一组类型中进行选择...您可以使用您想要的任何类型名称(大括号表示它是一种类型),因此您可以简单地执行以下操作:

@return {void}

虽然,这可能更正确对于 JavaScript:

@return {undefined}

I don't believe you have to choose from a set of types in JsDoc... you can use any type name you wish (the curly braces indicate it's a type), so you can simply do:

@return {void}

Although, this is probably more correct for JavaScript:

@return {undefined}
过气美图社 2024-10-20 08:56:25

查看他们使用的 ESlint 文档
@returns {void}

来源:http://eslint.org/docs /rules/valid-jsdoc

由于我需要为每个函数提供一个 @returns 来通过测试,以便为某些项目推送代码,这在我的情况下是必需的。

Looking at the ESlint docs they use
@returns {void}

Source: http://eslint.org/docs/rules/valid-jsdoc

Since I need to provide an @returns for each function to pass tests in order to push code for certain projects this is required in my case.

掩于岁月 2024-10-20 08:56:25

我发现这比省略 @returns:

@returns {} Nothing is returned.

甚至

@returns {} Nothing is returned because this is a broadcast receiver.

只是一个想法更明确。

I find this less ambiguous than leaving out the @returns:

@returns {} Nothing is returned.

or even

@returns {} Nothing is returned because this is a broadcast receiver.

Just an idea.

雨的味道风的声音 2024-10-20 08:56:25

为了帮助在其他答案之间做出决定,显式编写的 @return {void} 有一个好处。虽然@return可以省略,但对于文档编码员来说,看到@return {void}可以帮助记忆。它告诉编码人员返回文档已编写。如果没有编写@return,那么编码人员可能需要检查他是否忘记编写返回值文档或者该函数是否确实没有返回任何内容。

当然,返回值文档可能已经过时。这是编码人员无法直接从文档中得知的,需要阅读代码来验证。尽管如此,看到写入的返回值可以让编码人员确信文档是正确的,而不仅仅是匆忙编写的。

To help to decide between the other answers, there is one benefit in explicitly written @return {void}. Although @return can be omitted, for a documenting coder, seeing the @return {void} works as a memory aid. It tells the coder that the return documentation is written. If there is no @return written, then the coder might need to inspect did he forget to write the return value documentation or does the function truly return nothing.

Of course, the return value documentation might be outdated. That is something the coder cannot directly know from the docs and needs to read the code to verify. Still, seeing the return value written gives the coder a bit of certainty that the documentation is correct and not just hastily written.

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