-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Proposal: export as namespace
for UMD module output
#26532
Comments
Personal opinion, is that because this expression level syntax would only apply to UMD modules, that it is "dangerous" to deal with this like that. Because what would you emit for AMD, CommonJS or ES Modules? Having syntax that is only valid in one module format feels very anti-pattern for TypeScript. I would think that a triple slash directive would be a better way of solving this. There is already the AMD directive: ///<amd-module name="NamedModule"/> So why not just extend that to UMD and follow the suggestion above: ///<umd-module name="foo.bar.baz"/> |
The export var x = 3;
export as namespace Foo; export declare var x: number;
export as namespace Foo; // same syntax! |
Related: #20990 |
I'd take this to extremes wondering about straight transpilation of modules into namespaces (global objects) given a shape/schema defined in an entry point: // browser-index.ts
import * as _Core from "./core/index";
import * as _Components from "./components/index";
export namespace UI {
export import MyCoreThing = _Core.MyCoreThing;
}
export namespace Components {
export namespace UI {
export import MyComponentThing = _Components.MyComponentThing;
}
}
export as namespace Vendor.Awesomeness; // <- dots should be allowed because I'm lazy. When compiling against that, I'd expect to get everything bundled - with coherent aside typings - into <script>
var coreThing = new Vendor.Awesomeness.UI.MyCoreThing();
var componentThing = new Vendor.Awesomeness.Components.UI.MyComponentThing();
</script> That would be very useful for granular libraries distribution (e.g. webcomponent libs):
|
Current problem
TypeScript supports UMD output but does not support exporting as a global namespace.
Syntax
NamespaceExportDeclaration:
export
as
namespace
IdentifierPathBehavior
Note
namespace
does.export default X
works like CommonJSmodule.exports = X
whereas this proposal does not.Prior arts: Babel exactGlobals, Webpack multi part library, Rollup
output.name
option with namespace supportSee also
#8436
#10907
#20990
The text was updated successfully, but these errors were encountered: