I tried really hard to understand the explanation
found here about types and subclassing, but evidently I cannot understand things well enough and the compiler complains still, so I am hoping by giving my example someone can tell me what exactly is going on and where is my mistake.
I am constructing a custom button renderer and I want to override the declare method. It works as expected when provided as renderer option to the goog.ui.CustomButton constructor and rendering works fine, code compiles fine.
The problem is I want to force the type checking to make sure the component is indeed goog.ui.CustomButton and not just any goog.ui.Control. So I make the following param declaration:
/** @param {!goog.ui.CustomButton} button ... */
However the compiler says I am incorrectly overrideing the method:
js/client/ui.ButtonRenderer.js:61: WARNING - mismatch of the decorate property type and the type of the property it overrides from superclass goog.ui.ControlRenderer
original: function (this:goog.ui.ButtonRenderer, (goog.ui.Control|null), (Element|null)): (Element|null)
override: function (this:spo.ui.ButtonRenderer, (goog.ui.CustomButton|null), (Element|null)): (Element|null)
spo.ui.ButtonRenderer.prototype.decorate = function(control, element) {
I believe goog.ui.CustomButton is a subclass of goog.ui.Control. Also spo.ui.ButtonRenderer is a subclass of goog.ui.ButtonRenderer. What is the rule when overloading a method, the parameter should be the same, of the parameter should be a superclass of the original method or a subclass of the original method? I don't really get it at this point. The original method knows how to handle goog.ui.Control, goog.ui.CustomButton is subclass of it so shouldn't my class follow the pattern but refine what it can handle? Can this be done, is it correct?
Hopefully someone can explain where I am mistaking.