0

I have a type defintion file for one of my modules which has a defintion for a lot of interfaces. I am trying to break down the definition into multiple files for better organization

// original file - index.d.ts
declare module 'my-module' {
  interface A { }
  interface B { }
  interface C { }
  export interface D {
    a: A,
    b: B,
    c: C
  }
}

// the setup that I am looking for

// A.d.ts
export interface A {}

// B.d.ts 
export interface B {}

// index.d.ts
declare module 'my-module' {
  // import A.d.ts here
  // import B.d.ts here
}

How do i import A.d.ts and B.d.ts in index.d.ts ?

One of the ways i have seen it working is using a import() syntax, where I can do something like:

declare module 'my-module' {
   export interface D {
     a: import('../A.d.ts').A
     ...
   }
}

I also understand that a regular import on top of the file does not work as it changes the global declaration to a module, but why doesn't a import inside the declare keyword work ?

declare module 'my-module' {
  import { A } from '../A.d.ts';
  export interface D {
    a: A
    ...
  }
}
gaurav5430
  • 12,934
  • 6
  • 54
  • 111

0 Answers0