Feature Request: Allow "string" named external module declarations to be reopened

Topics: General
Apr 19, 2014 at 4:16 AM
I'm composing an application that uses AMD modules.

The testing uses the chai assertion library and a few plugins for it (chai-jquery / sinon-chai).

i want to import those as you would expect using require('chai') etc...
since the js files lie in an extra "libs" folder i use require.config to wire those up to the correct paths.
to make ts happy, i reference the .d.ts files and the module declaration in them is using the concrete string name instead of an identifier i.e. "chai-jquery".

Those plugin libraries provide functionality to the main chai library however which means that each of their header files declares the chai module again with the added functionality.

This works fine with identifier named modules, but when i want to use the "string" named ones, ts just tells me those can't be reopened...

So my question is: why not?
And can we have that feature?

Otherwise TS rocks ;)
Coordinator
Apr 21, 2014 at 4:43 PM
This is actually possible today, though you have to use a bit of a workaround to get there.

[externalModule.d.ts]
declare module MyModule {
    export var x: number;
}

declare module MyModule {
    export var y: string;
}

declare module "externalModule" {
    export = MyModule;
}
[useModule.ts]
import Mod = require("externalModule");

Mod.y;
Marked as answer by grollinger on 4/21/2014 at 12:36 PM
Apr 28, 2014 at 11:41 PM
This is possible but it does add new names into the global namespace and cause random collisions with your own code.

The nice thing about the string names is that they have their own namespace.