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


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.


Was this page helpful?
0 / 5 - 0 ratings

Related issues

yuit picture yuit  ·  3Comments

seanzer picture seanzer  ·  3Comments

wmaurer picture wmaurer  ·  3Comments

uber5001 picture uber5001  ·  3Comments

siddjain picture siddjain  ·  3Comments