Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Augmenting external module that is re-exported?

See original GitHub issue

TypeScript Version: 2.5.2


This can’t be demonstrated with a simple 1-file code example so I made a trivial project to demo it:

Instructions for how to run the demo and work around the issue are included on the README there.

When I include an interface in a node module’s main index.ts file, then it is open for merging with a declare module "my_npm_module" {} but when I move that interface into a local submodule and export it in the main index.ts with a export * from "./local_module"; then the downstream consumer breaks.

Expected behavior:

It seems to me that the point of being able to export from other modules is to keep downstream consumers protected from internal refactors and maintain an existing public API. So I expect to be able to augment an interface and have it behave the same whether or not it has been re-exported.

Actual behavior:

It looks like the interface gets forked into two definitions, the downstream module sees only the interface surface that was added and the upstream module only sees the interface surface it defined.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:13
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

ktutnikcommented, Mar 27, 2019

Look like this is bug in TypeScript 3.3.3333 I found that when using export star will cause augmentation failed. Workaround is manually export like below

export  { ClassA, ClassB, otherInstance, otherNamespace } from "my-cool-module"
chriseppsteincommented, Oct 1, 2017

@aluanhaddad Thanks for the reply. I’ve moved the code that needs to be augmented to the root of the node module. Not ideal, to say the least.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is a typescript module augmentation automatically exported in ...
I created a component library using material-ui and Typescript under the hood. I have used Typescript module augmentation in order to add ...
Read more >
Solve any external library error in TypeScript with module ...
The reason is you need to augment an export by its exported name, and default is a reserved word. Extending third-party modules using...
Read more >
Documentation - Declaration Merging - TypeScript
To merge the namespaces, type definitions from exported interfaces declared in each ... You can use module augmentation to tell the compiler about...
Read more >
How to augment an external "export = ..."? : r/typescript - Reddit
I am trying to augment the WebSocket class in @types/ws ( source here ). ... which are merged and exported with export =...
Read more >
Importing CommonJS · Publishing ES Modules ... Instead, we recommend the following approach e.g. to generate an absolute id for an external module:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found