I recently encountered an issue with a function that can accept a variable number of parameters.
After consulting the Google Closure Compiler wiki, I attempted to annotate the parameters using the @param
annotation as suggested.
/**
* Takes 2 or more strings and do something cool with them.
* @param {...string} var_args
* @return {string} the processed result
*/
function doSomethingCool() {
var len = arguments.length;
if (len < 2) {
throw Error('Need at least 2 arguments');
}
...
}
Issue
Upon compiling, a warning appeared stating:
JSC_INEXISTENT_PARAM: parameter var_args does not appear in doSomethingCool's parameter list at line 6 character 1
I tried using @param {string} arguments
, but encountered the same error.
Even attempting @param {string}
without specifying a variable name resulted in:
JSC_TYPE_PARSE_ERROR: Bad type annotation. expecting a variable name in a @param tag.
Inquiry
What went wrong in my annotation attempts and how should variable parameters be annotated for the Closure Compiler?