Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
TypeScript won't recognize cross-module type extensions
I'm trying to write a Node module that extends the functionality of another module (a peer dependency which I do not control) using a register function exposed by the other module. This adds additional methods to some types from the other library, and I have created a .d.ts file that contains those type extensions. However, when I later install both modules, TypeScript does not recognize the type extensions, even though it recognizes other type declarations from the same .d.ts file.
I have summarized my index.d.ts file below:
import "other-package/types";
declare global {
interface Context { /* ... */ }
const context: Context; // <-- This declaration is recognized
namespace OtherPackage {
interface ExtendedInterface extends ExtensionInterface { }
// ^ This declaration appears to be ignored
}
}
This is how the interface extensions would be typed if they were part of the end project, and they work in that context, but when moved into another module, they no longer work. Is there something different I'm supposed to do to get this to work?
0 comment threads