Closed
Description
We are using AMD modules in our JavaScript application. Application code base is growing and we have made a decision to move to TS for more type safety recently.
Problem
Consuming AMD modules written in JavaScript is too cumbersome.
/// <amd-dependency path="x" />
works for expressing the dependency, but in order to consume the dependecy from TS requires all kinds of trickery, which should not be the case for a common case of using TS and JS interchangeably.
Solution
Introduce name parameter to amd-dependecy comment.
/// <amd-dependency path="x" name="variableName" />
With this simple enhancement we can write much cleaner TS code:
/// <amd-dependency path="legacy/moduleA" name="moduleA"/>
declare var moduleA:MyType
moduleA.callStuff()
Generated JS code:
define(["require", "exports", "legacy/moduleA"], function (require, exports, moduleA) {
moduleA.callStuff()
});
Extra benefits
- Easy to use RequireJS loader plugins (Support non-code AMD modules #279)