Merging interfaces in namespace typescript

Viewed 390

I'm working on a project and I'm struggling with namespace merging. I have the below structure

// file a.d.ts
declare namespace A{
    interface IA{
       bar()
    }
    interface IB{
       //..stuff
    }
}
declare const foo: A.IA;
export = foo;
export as namespace foo;

When I import the above namespace in myfile.ts and try to access bar() it works fine.

// myfile.ts
import * as foo from 'a'
foo.bar() //works fine

Now I have another file b.d.ts, in which I want to add some more stuff to the existing namespace A

//file b.d.ts
declare namespace A{
    interface IA{
       function bar2()
    }
}

Since there are no top-level imports/exports in b.d.ts file, shouldn't it run at the global scope and merge both the IA interfaces? But I cant see the bar2() function in my myfile.ts

import * as foo from 'a'
console.log(foo); // output has only bar1() and no bar2()

I want a way to add the bar2() function to the IA interface in b.d.ts file. Can someone help me out with this

Thanks

0 Answers
Related