How to write a module declaration that adds another module declaration

I am trying to write TypeScript declarations for some existing AMD modules written in JavaScript.

The structure that I am trying to present is a “plug-in” model, where one module declares an interface and another module extends this interface with “plug-ins”. I am trying to follow the example of a module extension here , but this does not seem to allow me to create two separate modules.

Example:

  • The foo module defines the Foo interface and exports the singleton constant of this interface.
  • The foo-plugin module adds a new plug-in function to the Foo interface

On the consumer side, I want the behavior to be as follows:

// by importing this, I can use the foo singleton as type Foo with only the Foo
// functionality defined in "foo"
import { foo } from "foo";
// by also importing this, I can now use the additional Foo.plugin function defined by "foo-plugin" on the foo singleton
import "foo-plugin";

// this should compile if and only if the "foo-plugin" module is imported
foo.plugin();

? ?

+4

Source: https://habr.com/ru/post/1680363/


All Articles