I'm getting a lot of "Unknown type"
warnings when running a fairly large library through Closure Compiler, and they seem to occur when my types are declared in self-executing anonymous functions. There's nothing exotic about this, but if I strip the self-executing functions out, the type declarations seem to work (at least in this simple test).
I'm not sure if there's something wrong with my code annotations or if there's anything illegal in the code, but I think this is all kosher and the standard way to modularize an API.
The following test code creates a namespace (just a plain old JS object) and attaches an enum (an object literal) and a function to it.
var mynamespace = {};
(function (mynamespace) {
/**
* Some enum.
* @enum {number}
*/
mynamespace.SomeEnum = {
FOO: 1,
BAR: 2
};
/**
* Frazzle some type.
* @param {mynamespace.SomeEnum} qux The type to frazzle.
* @return {boolean} whether the operation succeeded.
*/
mynamespace.frazzle = function(qux) {
return true;
}
}(mynamespace));
// call it
mynamespace.frazzle(mynamespace.SomeEnum.FOO);
Looks fine, right? The closure compiler errors:
[jscomp] Compiling 1 file(s) with 37 extern(s)
[jscomp] X:\dev\solclientjs\sdk\tools\jscomptest.js:14: WARNING - Parse error. Unknown type mynamespace.SomeEnum
[jscomp] * @param {mynamespace.SomeEnum} qux The type to frazzle.