1

Closed

Duplicate Identifier Inconsistency

description

I think either both of these should not be an error OR both of these should be an error. I am leaning towards not being an error.
// Okay 
module X
{
    export class Y{     
    }
    export module Y{        
    }
}
// Error : Duplicate identifier
module X
{
    export module Y{        
    }
    export class Y{     
    }
}
Closed Sep 20, 2013 at 1:25 AM by danquirk

comments

danquirk wrote Sep 20, 2013 at 1:24 AM

This is by design. You are allowed to merge declarations with the same name in certain cases. In this case, a class followed by a module is allowed, the module adds new values to the static side of the class. In the second case it is not allowed due to code generation limitations. You can see the specifics in section 10.5 Declaration Merging in the language specification. For a concrete example:
class Y {
    foo: string;
}
module Y {
    export var bar: number;
}

var a: number = Y.bar;
var b: string = Y.foo; // error, foo is an instance value
var y = new Y();
var c: number = y.bar; // error, bar is a static value
var d: string = y.foo;