Search code examples
typescriptamd

is there a Typescript external module reference available inside the module?


In javascript, when I define an AMD module I create and return a reference to the exposed portions of the module. When I use Typescript, I 'export' items, which causes them to be added to the 'exports' variable.

//javascript module
define(["require", "exports"], function(require, exports) {
    exports.message = function(s) {
        console.log(s);
    }
}

In Typescript, I would like to get a reference to the external module from within the module, while it's being defined. Basically, I'd like access to the generated 'exports' variable, but can't find a way. Among other reasons, I'd like to be able to call Duradal's system.getModuleId and pass the current module.

Thanks


Solution

  • declare var exports;
    
    export var n = 4;
    console.log(exports);
    

    Produces:

    define(["require", "exports"], function(require, exports) {
        exports.n = 4;
        console.log(exports);
    });