Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create non-anonymous AMD Modules in TypeScript

Tags:

typescript

Is there a way to create non-anonymous AMD Modules in Typescript. When I define a module like this:

export module Bootstrapper {
  export function run() {
    var i = 0;
  }
}

the generate code is:

define(["require", "exports"], function(require, exports) {
  (function (Bootstrapper) {
    function run() {
        var i = 0;
    }
    Bootstrapper.run = run;
  })(exports.Bootstrapper || (exports.Bootstrapper = {}));
})

How can I define a non-anomymous module like this:

define('bootstrapper', ["require", "exports"], function(require, exports) {
  (function (Bootstrapper) {
    function run() {
        var i = 0;
    }
    Bootstrapper.run = run;
  })(exports.Bootstrapper || (exports.Bootstrapper = {}));
})
like image 340
mvbaffa Avatar asked Oct 18 '12 13:10

mvbaffa


3 Answers

This feature was recently added to the TypeScript master branch via this pull request. Declaring an AMD module name is with the following reference comment:

/// <amd-module name='MyModuleName'/>

will produce the following JavaScript:

define("MyModuleName", ["require", "exports"], function (require, exports) { ... }

like image 134
Gabriel Isenberg Avatar answered Oct 17 '22 14:10

Gabriel Isenberg


As you can see in the file emitter.ts at line 1202 (make a search for " var dependencyList = ") there is no implementation for it.

You can open an issue on codeplex about it.

like image 24
Diullei Avatar answered Oct 17 '22 14:10

Diullei


As of TS 0.9.x it is not possible to name an AMD module. The TS compiler will only generate a define statement in the format

define( ['dep1', 'dep2', ..., 'depN'], function( __dep1__, __dep2__, ..., __depN__ ) {... } );

discussion on the TS forums : https://typescript.codeplex.com/discussions/451454

like image 37
Robert Slaney Avatar answered Oct 17 '22 16:10

Robert Slaney