Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return void in JsDoc?

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 ...  */ 
like image 909
Tower Avatar asked Jan 21 '11 13:01

Tower


2 Answers

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.

like image 175
Brent Robinson Avatar answered Oct 02 '22 16:10

Brent Robinson


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} 
like image 35
David Tang Avatar answered Oct 02 '22 14:10

David Tang