在 JsDoc 中是否有指定的方法来声明返回 void 的方法或函数?目前我认为void
是默认返回值,其他返回值必须具体提供:
/**
* @return {Integer} The identifier for ...
*/
在 JsDoc 中是否有指定的方法来声明返回 void 的方法或函数?目前我认为void
是默认返回值,其他返回值必须具体提供:
/**
* @return {Integer} The identifier for ...
*/
根据 Google 的 Closure Compiler 的文档,如果没有返回任何内容,则应省略 @return 注释。
如果没有返回值,请不要使用@return 标记。
来源: https ://developers.google.com/closure/compiler/docs/js-for-compiler#tags
然而,进一步的文档还指出 returnType 和 returnDescription 是可选参数。
returnType - 可选:返回值的类型。
returnDescription - 可选:任何附加描述。
来源: https ://code.google.com/p/jsdoc-toolkit/wiki/TagReturns
您可以省略返回注释,也可以在不包含任何参数的情况下包含它。
我不相信你必须从 JsDoc 中的一组类型中进行选择......你可以使用任何你想要的类型名称(花括号表示它是一种类型),所以你可以简单地做:
@return {void}
虽然,这对于 JavaScript 可能更正确:
@return {undefined}
查看他们使用的 ESlint 文档
@returns {void}
来源:http ://eslint.org/docs/rules/valid-jsdoc
由于我需要@returns
为每个函数提供一个通过测试以便为某些项目推送代码,这在我的情况下是必需的。
If you need to say out loud that nothing is returned, you can say that in the free-form description. This is useful to clarify situations where a user might expect something to be returned. Of course proper naming of the function and the parameters should alone make the expected return type apparent, but it might not always be possible.
/**
* This is a funny function. Returns nothing.
* @param {string} a joke.
*/
var funny = function (joke) {
console.log(joke);
};
我发现这比省略@returns
:
@returns {} Nothing is returned.
甚至
@returns {} Nothing is returned because this is a broadcast receiver.
只是一个想法。