Typescript: External modules with AMD always requires "exports" even when it is not used

Created on 13 Sep 2014  ·  6Comments  ·  Source: microsoft/TypeScript

Here's a small external module that explicitly exports a module:

module Foo {
    export var foo = 42;
}
export = Foo;

The code generated for this is:

define(["require", "exports"], function(require, exports) {
    var Foo;
    (function (Foo) {
        Foo.foo = 42;
    })(Foo || (Foo = {}));

    return Foo;
});

This feels like bad AMD since you are requiring the "exports" magic dependency, but then not using it and instead returning Foo directly.

It's annoying for minimal AMD loaders since they can't assume the object return of your module is your "exports" object and have to guess that you really meant to return something that overrode the "exports" object you asked for.

Furthermore, why bother declaring a dependency on 'require' when it's not used?

Suggestion help wanted

Most helpful comment

All 6 comments

Seems like a reasonable proposal

Approved

Has this been implemented yet? I need it...

@amandaol the tags on the issue indicate that it is up to the community to implement. Coupled with the issue still being open means that the it hasn't been implemented.

For what it's worth, we now use amdextract in our build pipeline after tsc to remove the unnecessary require and exports from emitted JS.

https://github.com/mehdishojaei/amdextract

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Roam-Cooper picture Roam-Cooper  ·  3Comments

Antony-Jones picture Antony-Jones  ·  3Comments

zhuravlikjb picture zhuravlikjb  ·  3Comments

manekinekko picture manekinekko  ·  3Comments

DanielRosenwasser picture DanielRosenwasser  ·  3Comments