用任何类型注释“零个”或“多个”参数;谷歌闭包编译器

Annotating "zero or more parameters with any type" for Google Closure Compiler

本文关键字:参数 谷歌 闭包 编译器 多个 注释 任何 零个 类型      更新时间:2023-09-26

我有一个与jQuery.noop, angular.noopgoog.nullFunction相同的函数:它不做任何事情并且返回未定义,但以callback(successFn || noop);的形式使用它很方便。

可以使用任意数量的任意类型的参数(0或更多)来调用。

我现在是这样做的:

/**
 * @param varArgs {...*}
 */
var noop = function(varArgs) {};

问题:当没有参数调用时,谷歌闭包编译器给我这个:

Function noop: called with 0 argument(s). 
Function requires at least 1 argument(s) and no more than 1 argument(s).

有趣的是……nullFunction为闭包编译器做了注释,但它的注释也有缺陷,当带一个或多个参数调用它时,它会抛出错误:

Function noop: called with 1 argument(s).
Function requires at least 0 argument(s) and no more than 0 argument(s).

问题:我如何正确注释我的noop函数?

从文档来看,语法是:

/**
 * @param {...*} varArgs
 */

首先输入变量的类型,然后是它的名称。在测试之后,你的例子确实给出了一个错误,但当使用正确的顺序时,它不会。