Typescript declaration merging for external module with export as namespace

Viewed 172

I'm using a external library that has a DefinitelyTyped type definition in @types/external-module-x/index.d.ts

import { SomeEnumA, SomeInterfaceA } from './modules/folder1';
import { SomeInterfaceB } from './modules/folder2';

export const Cat: SomeInterfaceB;

export {
  SomeEnumA,
  SomeInterfaceA,
  SomeInterfaceB
};

export as namespace ns1;

It is missing some type definitions so I wanted to do a declaration merging to make it happen. I've tried as below because I need to access the new type with ns1.MyNewVariable. But I'm not able to get it working. ns1.MyNewVariable is not there My attempt looks like this -

declare module 'external-module-x' {
  export namespace ns1 {
    export const MyNewVariable: string;

    export interface MyNewInterface {
      property1: string;
      property2: boolean;
    }
  }
}

Appreciate if anyone can point me to the right direction. Thanks

0 Answers
Related