Javascript goog.Timer.callOnce不符合形式参数:Google Closure

Javascript goog.Timer.callOnce不符合形式参数:Google Closure,javascript,google-closure-compiler,google-closure,google-closure-library,Javascript,Google Closure Compiler,Google Closure,Google Closure Library,使用goog.Timer.callOnce时,即使我认为我已正确声明了所有内容,也会出现形式参数不匹配的错误 goog.Timer.callOnce(/** @type {function} */ this.doSomething,0,this); 方法定义如下所示 /** * @param {!goog.events.Event} e */ model.someModel.prototype.doSomething = function(e){ } 错误看起来像 ERROR - actu

使用goog.Timer.callOnce时,即使我认为我已正确声明了所有内容,也会出现形式参数不匹配的错误

goog.Timer.callOnce(/** @type {function} */ this.doSomething,0,this); 
方法定义如下所示

/**
* @param {!goog.events.Event} e
*/
model.someModel.prototype.doSomething = function(e){
}
错误看起来像

ERROR - actual parameter 1 of goog.Timer.callOnce does not match formal parameter
==> default: [ERROR] found   : function (this:model.someModel, goog.events.Event): undefined
==> default: [ERROR] required: (function (this:model.someModel): ?|null|{handleEvent: function (): ?})
==> default: [ERROR] goog.Timer.callOnce(/** @type {function} */doSomething,0,this);

我还尝试了类型转换
/**type{function()}*/
,但即使这样也不起作用

编译器期望一个不带参数的函数(因为goog.Timer不会传递任何参数),而您传递的函数期望一个参数。更改函数,使其不接受参数,或使参数为可选参数:

/**
 * @param {!goog.events.Event=} opt_e
 */
model.someModel.prototype.doSomething = function(opt_e) {
  if (opt_e) {
    ...
  } else {
    ...
  }
}

注意:除非添加括号,否则编译器不会理解您正在尝试进行类型转换:
/**type{function()}*/(this.doSomething)
。而且,
函数
不是一种类型<代码>!Function(大写F)表示“任何函数”,而
Function()
表示“不带参数的函数”