Skip to content

Simplify JavaScript AMD module import workflow #1908

Closed
@v3nom

Description

@v3nom

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedA PR has been merged for this issueSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions