Re-exporting namespace declarations in ES6 ambient declaration
See original GitHub issueRight now many declaration files take this form:
declare namespace MyLib {
}
declare module 'myLib' {
export = MyLib;
}
However, there doesn’t seem to be an equivalent for ES6 modules:
declare module 'myLib' {
export default MyLib; // this works for exporting the default, but other exported items in MyLib are not considered to be named exports of the ES6 module
export * from MyLib; // this is essentially what I'm trying to accomplish
}
Issue Analytics
- State:
- Created 8 years ago
- Reactions:20
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Documentation - Namespaces and Modules - TypeScript
How to organize code in TypeScript via modules or namespaces. ... file could not be found, then the compiler will look for an...
Read more >Re-export namespace from external module to global in ...
Here I'll post the piece of code to better explain my problem. //SomeClass.d.ts - I have to declare classes like this due to...
Read more >Modules - TypeScript
Conversely, a file without any top-level import or export declarations is treated as a ... To do so, we use a construct similar...
Read more >Jagruti Metaliya on Twitter: "- To do so, we use a construct similar to ...
Default export class and function declaration names are optional. ... We call declarations that don't define an implementation “ambient”.
Read more >How To Use Namespaces in TypeScript | DigitalOcean
This means that multiple declarations of the same namespace will be merged into a single declaration. This can add flexibility to a namespace...
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
(re)exporting namespaces using existing export syntax would be helpful.
Exporting
Allowing the above, could it help getting rid of the annoying Export declaration is not permitted in a namespace error?
Would love to logically organise a large component using namespace and still maintain the ability to expose needed members to the outside…
(Re)exporting namespaces or interfaces is really reasonable.
current status
You can use the follow style:
a.d.ts
index.d.ts
However, you can’t use it in a namespace which is incompatible with scene 3
And it usage is quite limited.
possible scene of re-exporting
For example, I may define several definiation files, assume the library name is MyLib:
a.d.ts
b.d.ts
scene 1 (re-export namespace as sub namespace)
index.d.ts (MyLib definition)
index.tests.ts
scene 2 (merge the namespaces)
index.d.ts (MyLib definition)
index.tests.ts
scene 3 (normal for node.js modules)
index.d.ts (MyLib definition)
index.tests.ts
scene 4 (like scene2 in scene3)
…