This project is read-only.

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?

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:

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

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.
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: