Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@override a method, Google Closure Compiler

I'm trying to override a method of a superclass and compile the code using Google Closure Compiler but I'm getting a warning about wrong types.

/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) {

As you can see, I'm not changing the type of the argument accepted by the super method nor do I change the returned type.

Does anyone know how to resolve this issue? thanks.

To clarify, here are the definitions of the individual methods.

/**
 * @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) { ... }
like image 728
J. K. Avatar asked Mar 03 '26 17:03

J. K.


1 Answers

Overridden methods must have the same (or at least very similar) signatures. Specifically, Subclass methods must be able to be used anywhere the base class could be used. See a full discussion: https://groups.google.com/d/topic/closure-compiler-discuss/o_CMZAvFOLU/discussion

The error message you post above shows that the overriding method has more required arguments than the original which is specifically not allowed. You could however have more optional arguments.

like image 124
Chad Killingsworth Avatar answered Mar 05 '26 08:03

Chad Killingsworth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!