Wrapping modules for customer loaders

Topics: General, Language Specification
Oct 25, 2013 at 12:14 AM
Hi, I have my own custom loaders for javascripts and I noticed that "require()" automatically wraps the modules. How can I implement my own functions to control this?

Thanks.
Oct 28, 2013 at 5:14 PM
@jamesnw, did you mean that when you write
export class Foo {
}
This gets compiled into
define(["require", "exports"], function(require, exports) {
    var Foo = (function () {
        function Foo() {
        }
        return Foo;
    })();
    exports.Foo = Foo;
});
And you want to get hold of Foo?
Oct 28, 2013 at 6:29 PM
Edited Oct 28, 2013 at 6:31 PM
I started a question on the modules here related to this as well: http://stackoverflow.com/questions/19637586/merging-two-exported-modules

I want to be able to import a module from file1 in file2 so that the two internal modules merge together. For example:
File1:
export module A {
    export module B {
        export class X {
        }
    }
}

File2:
import mod = require("test1");
import A = mod.A;

export module A {
    export module B {
        export class Y extends X {
        }
    }
}
But that doesn't work. If it did, I could create my own "define()" method with my own loader, and still allow the modules to "see" each other" - this way the end user of my API can choose which modules they want to put together.
Coordinator
Oct 29, 2013 at 4:53 PM
We don't currently support multi-file external modules, but it's on our radar. A few of TypeScript team members have hit this issue as well in our own for-fun side projects, which makes it even more personal :)
Oct 29, 2013 at 4:54 PM
Edited Oct 29, 2013 at 4:56 PM
Cool beans! Good to know. ;)

FYI: Related proposal: https://typescript.codeplex.com/workitem/1846