Javascript 变量参数的Google Closure Compiler@param注释

Javascript 变量参数的Google Closure Compiler@param注释,javascript,annotations,google-closure-compiler,jsdoc,Javascript,Annotations,Google Closure Compiler,Jsdoc,我有一个函数,可以接受数量可变的参数 根据,这是使用@param注释实现的方法 /** * 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 (l

我有一个函数,可以接受数量可变的参数

根据,这是使用
@param
注释实现的方法

/**
 * 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');
    }

    ...
}
/**
*需要2个或更多的字符串,并用它们做一些很酷的事情。
*@param{…string}var_args
*@return{string}处理结果
*/
函数doSomethingCool(){
var len=arguments.length;
if(len<2){
抛出错误('至少需要2个参数');
}
...
}
问题 当我尝试编译它时,我看到以下警告:
JSC\u不存在\u参数:参数var\u args没有出现在DoSomethingTool的参数列表的第6行字符1

因此,我尝试了
@param{string}参数
,但出现了相同的错误

我还尝试了没有变量名的
@param{string}
。我得到:
JSC\u TYPE\u PARSE\u错误:错误的类型注释。@param标记中应包含变量名。

问题:
我做错了什么?如何为闭包编译器注释变量参数?

您的
var_args
需要实际出现在参数列表中,这就是错误告诉您的

/**
 * Takes 2 or more strings and do something cool with them.
 * @param {...string} var_args
 * @return {string} the processed result
 */
function doSomethingCool(var_args) {}
闭包编译器将识别它从未被引用,并在编译期间将其删除

如果将其列在那里让您感到不安,您可以使用
@type
注释:

/**
 * Takes 2 or more strings and do something cool with them.
 * @type {function(...string):string}
 */
function doSomethingCool() {}
如果确实需要正确的类型检查,请对函数进行注释,使其包含2个或更多字符串:

/**
 * Takes 2 or more strings and do something cool with them.
 * @type {function(string, string, ...string):string}
 */
function doSomethingCool() {}

您的
var_args
需要实际出现在参数列表中,这就是错误告诉您的

/**
 * Takes 2 or more strings and do something cool with them.
 * @param {...string} var_args
 * @return {string} the processed result
 */
function doSomethingCool(var_args) {}
闭包编译器将识别它从未被引用,并在编译期间将其删除

如果将其列在那里让您感到不安,您可以使用
@type
注释:

/**
 * Takes 2 or more strings and do something cool with them.
 * @type {function(...string):string}
 */
function doSomethingCool() {}
如果确实需要正确的类型检查,请对函数进行注释,使其包含2个或更多字符串:

/**
 * Takes 2 or more strings and do something cool with them.
 * @type {function(string, string, ...string):string}
 */
function doSomethingCool() {}

实际上,我希望坚持使用
@param
注释,以确保所有函数的一致性。看起来我别无选择,只能对这些函数使用
@type
注释。或者,您也可以更高效地编写代码。使用
arguments
对象通常被认为是不好的做法,因为它会增加该函数的额外开销,并阻止某些JIST优化。如果您需要向
doSomethingCool
传递数量可变的内容,那么只需传递
doSomethingCool
一个可变长度数组作为第一个参数。我实际上希望坚持使用
@param
注释,以确保所有函数的一致性。看起来我别无选择,只能对这些函数使用
@type
注释。或者,您也可以更高效地编写代码。使用
arguments
对象通常被认为是不好的做法,因为它会增加该函数的额外开销,并阻止某些JIST优化。如果需要向
doSomethingCool
传递数量可变的内容,则只需传递
doSomethingCool
可变长度数组作为第一个参数。