Mihai Tomescu
Mihai Tomescu

Reputation: 1607

Augmenting external interface

I'm trying to augment the types of convict. Currently the definitions export convict using:

namespace convict { ... }
interface convict { ... }
declare var convict: convict;
export = convict;

So I augmented the interface (in ./types/convict/index.d.ts):

declare module 'convict' {
  interface convict {
    <T>(
      config: convict.Schema<T> | string,
      options?: { env: Record<string, string> }
    ): convict.Config<T>;
  }
}

However this interface is not picked up when importing the default export convict. It seems this is caused by export = convict and declare var convict: convict. However I can import the augmented interface directly:

// Default import fails - same interface as @types/convict
import convict from 'convict';

// Import interface directly is ok - convict interface is augmented
import { convict } from 'convict';

Can anyone help me understand why export = convict and declare var convict: convict ignores the augmented interface?

Upvotes: 0

Views: 161

Answers (1)

Mihai Tomescu
Mihai Tomescu

Reputation: 1607

According to Titian's comment this is not possible because the export assignment limits the visibility to only the exported declaration - the other declarations are private and so they can't be augmented.

Upvotes: 1

Related Questions