export as namespace doesn't support nesting namespaces
See original GitHub issueI’m using rollup to generate a UMD module from my TypeScript source. It’s part of a bigger product, so one component exports to a root namespace (e.g. mylib
) and another exports to a namespace nested under that (e.g. mylib.plugins.myplugin
). Rollup is generating the necessary UMD logic to walk down from the global scope creating namespaces as needed, but I can’t model that in my TypeScript d.ts
file.
The export as namespace
syntax is working great in the first case, but not the second. It looks like TypeScript doesn’t support nested namespaces for this purpose. Is this by design or just an omission?
TypeScript Version: 2.7.0-dev.20180103
Code: Two files, a d.ts
containing an export as namespace foo.bar
declaration and a script that references it.
declaration.d.ts
export var baz;
export as namespace foo.bar;
app.ts
console.log(foo.bar.baz);
Compile with: tsc .\test.d.ts .\main.ts
Expected behavior: The file compiles correctly to the following JS:
console.log(foo.bar.baz);
Actual behavior: Error
declaration.d.ts(3,24): error TS1005: ';' expected.
If I change declaration.d.ts
to use export as namespace foo
(and update app.ts
as needed), the compilation succeeds.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:14
- Comments:5 (1 by maintainers)
What about this:
In this case you could avoid making it global and just use it after a normal ES6 import.
My temp workaround is
Results in
Vendor.sdk.SDK
, which I build by Webpack. Writingexport as namespace Vendor.sdk
inSDK.ts
would be so much better.