External modules with AMD always requires "exports" even when it is not used
See original GitHub issueHere’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?
Issue Analytics
- State:
- Created 9 years ago
- Reactions:2
- Comments:6 (3 by maintainers)
Top Results From Across the Web
New es6 syntax for importing commonjs / amd modules i.e. ...
A module that uses export = to export another module (be that an internal or external module) can be imported using the new...
Read more >Writing Modular JavaScript With AMD, CommonJS & ES ...
Understanding AMD: require(). // Consider 'foo' and 'bar' are two external modules; // In this example, the 'exports' from the two modules loaded...
Read more >AMD is better for the web than CommonJS modules | Blog
AMD is better for the web than CommonJS modules ... exports.foo = foo;. The beauty of CommonJS modules is how simple they are,...
Read more >Module Methods
If dependencies are not provided, factoryMethod is called with require , exports and module (for compatibility!). If this function returns a value, this...
Read more >JavaScript modules - MDN Web Docs
This guide gives you all you need to get started with JavaScript module syntax. A background on modules. JavaScript programs started off pretty ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
SO question I asked regarding this: https://stackoverflow.com/questions/44836084/omit-require-and-exports-from-typescript-emitted-amd-dependencies
@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.