mvbaffa
mvbaffa

Reputation: 1031

Create non-anonymous AMD Modules in 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 = {}));
})

Upvotes: 10

Views: 730

Answers (3)

Gabriel Isenberg
Gabriel Isenberg

Reputation: 26321

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) { ... }

Upvotes: 6

Robert Slaney
Robert Slaney

Reputation: 3722

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

Upvotes: 1

Diullei
Diullei

Reputation: 12414

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.

Upvotes: 2

Related Questions