Unable to use JavaScript objects as module names

Topics: General
Mar 5, 2013 at 10:53 PM
I've got the following module:

module Kiwi.Components.Math

.. with a class inside of it set for export. But now I can't access the JavaScript Math object within my methods, i.e. Math.random(), Math.PI, etc. Visual Studio complains it can't find those properties on 'Math' (which I assume it's incorrectly referring to the module).

Is this a VS/compiler bug? Or will it never be fixed? I.e. I need to avoid the use of 'Math' in a module name. I can understand if my module was just called "Math" but I was hoping the depth of it would have avoided this issue.
Mar 5, 2013 at 10:54 PM
Also can someone fix the really annoying line-breaking that happens on this forum now, cutting off words mid flow and not wrapping them properly!
Coordinator
Mar 6, 2013 at 3:20 PM
TypeScript follows JavaScript in its approach to scoping and shadowing. If you have an example like this:
module MyModule {
    class Math {
        constructor() {
            var y = Math.cos(3);
        }
    }
}
You'll get an error because the class 'Math' is shadowing the global Math. To avoid this shadowing, you need another way to refer to the name before it's shadowed. For example, you could do this as a workaround:
var Math2 = Math;
module MyModule {
    class Math {
        constructor() {
            var y = Math2.cos(3);
        }
    }
}