Annotating "zero or more parameters with any type" for Google Closure Compiler
I have a function that is the same as jQuery.noop
, angular.noop
and goog.nullFunction
: it does nothing and returns undefined, but it is convenient to look at callback(successFn || noop);
.
It can be called with any number of arguments (0 or more) of any type.
Here's how I have it now:
/**
* @param varArgs {...*}
*/
var noop = function(varArgs) {};
Problem: When called with no arguments, the Google Closure compiler gives me this:
Function noop: called with 0 argument(s).
Function requires at least 1 argument(s) and no more than 1 argument(s).
The funny thing is that goog.nullFunction is annotated for Closure Compiler, but its annotation is also wrong, it throws errors when it called one or more arguments:
Function noop: called with 1 argument(s).
Function requires at least 0 argument(s) and no more than 0 argument(s).
Question: How can I annotate the function correctly noop
?
source to share
From the documentation, the syntax is:
/**
* @param {...*} varArgs
*/
You first enter the type of the variable and then the name. After the test, your example gives an error, but when using the correct ordering it is not.
source to share