Here is an example:
/** @constructor */
function A() {}
(function(){
function private_fn(num){
alert(num);
}
/** @param {number} num A number */
A.prototype.foo = function(num) {
private_fn(num);
}
})();
new A().foo("Hello"); // Why does this not give me a warning?? I
defined the parameter as a number.
I believe it will work if you put the call "new A().foo('hello')" into
a function (any function).
The basic problem is that type inference could literally take forever
(i.e., you can rigorously prove that no matter how good the type
inference is, the compiler will always be able to find more type
information). So there has to be some point where Closure Compiler
throws up its hands and says it's going to stop trying.
The general (over-simplified) rule of thumb is that it will give up
whenever it has to jump back and forth between the global scope and a
local scope. (i.e., if a property in the global scope needs something
in a local scope which needs something in the global scope).
Nick
Or, perhaps, to put this more simply, it will give up if it finds a
cycle between two scopes.
Nick
Yes - it will work if I do this.
function test() {
new A().foo("Hello"); // This now gives me the warning