microsoft / microsoft/TypeScript
export as namespace doesn't support nesting namespaces
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
I'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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal declaration.d.ts and app.ts reproduction, then run tsc .\test.d.ts .\main.ts to confirm the TS1005 error for export as namespace foo.bar. Trace how export as namespace is parsed and validated; done means nested namespaces compile and preserve the expected foo.bar.baz usage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100