I've been encountering the "Bad type annotation" when trying to use a custom namespace. I've distilled the problem down into a simple example that fails on the online closure compiler when using Advanced mode.Is there something obvious I'm missing here? Thanks in advance for any suggestions.Here's the error:JSC_TYPE_PARSE_ERROR: Bad type annotation. Unknown type ns.myClass at line 15 character 13
/** @return {ns.myClass} */
^And here's the test case I ran through the online Closure Compiler in Advanced mode:// ==ClosureCompiler==// @compilation_level ADVANCED_OPTIMIZATIONS// @output_file_name default.js// @formatting pretty_print// ==/ClosureCompiler==// ADD YOUR CODE HEREvar ns1 = {};ns1.ns2 = {};
var myNameSpace = ns1.ns2;(function (ns) {/** @constructor */ns.myClass = function () {this.sampleProp = 'Hi there';}ns.myClass.prototype = {/** @return {ns.myClass} */getMe : function () {return this;}}})(myNameSpace);var myInstance = new myNameSpace.myClass();myInstance.getMe();--
---
You received this message because you are subscribed to the Google Groups "Closure Compiler Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to closure-compiler-d...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Thanks, John. I was afraid the answer would look like that: in the "real world" code I use a more complicated method of creating the namespace (as listed in Test-Driven JavaScript Development by Christian Johansen) than the stripped-down version I used in the example. Here's the actual namespace generation. I guess I'll have to update my code to build up the namespace instead./** @const */ var myNameSpace = (function () {function namespace(string) {var object = this;var levels = string.split('.');for (var i = 0, l = levels.length; i < l; i++) {if (typeof object[levels[i]] === 'undefined') {object[levels[i]] = {};}object = object[levels[i]];}return object;}return { namespace: namespace };}());