Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External modules with AMD always requires "exports" even when it is not used #669

Open
xirzec opened this issue Sep 12, 2014 · 6 comments
Open
Labels
Help Wanted You can do this Suggestion An idea for TypeScript
Milestone

Comments

@xirzec
Copy link
Member

xirzec commented Sep 12, 2014

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?

@RyanCavanaugh RyanCavanaugh added In Discussion Not yet reached consensus Suggestion An idea for TypeScript labels Sep 15, 2014
@RyanCavanaugh
Copy link
Member

Seems like a reasonable proposal

@RyanCavanaugh RyanCavanaugh added Help Wanted You can do this and removed In Discussion Not yet reached consensus labels Apr 27, 2015
@RyanCavanaugh RyanCavanaugh added this to the Community milestone Apr 27, 2015
@RyanCavanaugh
Copy link
Member

Approved

@RoyTinker
Copy link

SO question I asked regarding this: https://stackoverflow.com/questions/44836084/omit-require-and-exports-from-typescript-emitted-amd-dependencies

@amandaol
Copy link

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

@kitsonk
Copy link
Contributor

kitsonk commented Nov 30, 2018

@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.

@RoyTinker
Copy link

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

@RyanCavanaugh RyanCavanaugh modified the milestones: Community, Backlog Mar 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

5 participants