How to return emptiness to JsDoc?

Is there a way to declare a method or function to return void in JsDoc? I currently believe void is the default return value, and other return values โ€‹โ€‹should be specified:

 /** * @return {Integer} The identifier for ... */ 
+46
javascript ide jsdoc
Jan 21 '11 at 13:15
source share
4 answers

I donโ€™t think that you need to choose from a set of types in JsDoc ... you can use any type name you want (curly braces indicate the type), so you can just do:

 @return {Void} 

Although probably this is more correct for JavaScript:

 @return {undefined} 
+48
Jan 21 '11 at 13:20
source share

Closure Compiler

According to the Google Closure compiler documentation, if nothing returns, the @return annotation should be omitted.

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

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

JSDoc toolkit

However, additional documentation also states that 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 can either leave the return annotation or enable it without any parameters.

+64
Dec 18 '13 at 5:04 on
source share

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

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

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

+1
Aug 02 '17 at 2:29 on
source share

If you need to say out loud that nothing returns, you can say that in the description of the free form . This is useful for clarifying situations where the user can expect something to be returned. Of course, the proper assignment of a function name and parameters should make the type of expected return obvious, but this may not always be possible.

 /** * This is a funny function. Returns nothing. * @param {string} a joke. */ var funny = function (joke) { console.log(joke); }; 
0
Mar 10 '15 at 8:24
source share



All Articles