Re: [closure-compiler-discuss] Type annotations for nested constructors

58 views
Skip to first unread message

Nick Santos

unread,
Sep 3, 2012, 12:57:21 PM9/3/12
to closure-comp...@googlegroups.com
These types aren't really addressable from the global scope.

The first one is lexically hidden from the global scope.

The second one is a property of an instance of "Obj", not a property
of the function "Obj". That means there could potentially be many
different types, one for each Obj you instantiate.

What problem are you actually trying to solve? In most languages I've
seen with "inner" types, you're explicitly using with scope to prevent
people from referring to it outside the class.

Nick

On Sun, Sep 2, 2012 at 10:27 PM, <andrew.e...@gmail.com> wrote:
> Hi all,
>
> I am just starting with the closure compiler and I am trying to wrap my head
> around how type names are specified in type annotations. What I am asking
> about are perhaps corner cases, but these are just the kinds of things that
> keep me up at night.
>
> Consider this not particularly realistic example:
>
> var obj = function() {
> /** @constructor */
> var Constr = function() { }
> return Constr;
> };
>
> /** @constructor */
> var Obj = function() {
> /** @constructor */
> this.Constr = function() { }
> }
>
> /** @type {Constr} */
> var x1;
>
> /** @type {Obj.Constr} */
> var x2;
>
> /** @type {obj.Constr} */
> var x3;
>
> I get warnings when compiling on x1, x2, and x3. How should I specify the
> type annotations for both of the Constr types?
>
> Thanks,
> Andrew
Reply all
Reply to author
Forward
0 new messages