3

我正在尝试覆盖超类的方法并使用 Google Closure Compiler 编译代码,但我收到有关错误类型的警告。

/Users/Jan/dev/cro/public/app/js/LibraryController.js:55: WARNING -
  mismatch of the setState property type and the type of the property it overrides
  from superclass app.Controller
original: function (this:app.Controller, Object): undefined
override: function (this:app.LibraryController, Object, string, string): undefined
app.LibraryController.prototype.setState = function (state, section, article) {

如您所见,我没有更改 super 方法接受的参数类型,也没有更改返回的类型。

有谁知道如何解决这个问题?谢谢。

为了澄清,这里是各个方法的定义。

/**
 * @param {!Object} state The new state.
 */
app.Controller.prototype.setState = function (state) { ... };

/**
 * @param {!Object} state The new state.
 * @param {string} section A section ID.
 * @param {string} article An article ID.
 * @override
 */
app.LibraryController.prototype.setState = function (state, section, article) { ... }
4

1 回答 1

4

被覆盖的方法必须具有相同(或至少非常相似)的签名。具体来说,子类方法必须能够在任何可以使用基类的地方使用。查看完整的讨论:https ://groups.google.com/d/topic/closure-compiler-discuss/o_CMZAvFOLU/discussion

您在上面发布的错误消息表明,覆盖方法比原始方法具有更多必需的参数,这是明确不允许的。但是,您可以有更多可选参数。

于 2012-10-25T13:07:27.767 回答