0

As soon as I'm importing Driver interface from api/event module I get an error: Cannot find module '@api/driver' when i try to import it.

import { Driver } from "@api/event";

declare module '@api/driver' {
  interface GetDriversResponse {
    drivers: Driver[];
  }
}

The error is fixed as soon as I remove the import statement.

Here is how many api/event module looks

declare module '@api/event' {
  interface Driver {
    name: string;
    id: number;
    org: string;
  }
}

Do I need to change something in the ts config?

Nitish Anand
  • 143
  • 1
  • 9

1 Answers1

0

When you use import or export in your Typescript file, it automatically becomes a module. When you do that, you have to import it in either files as a module. If you leave out any import/export statements, use the declare keyword and end your file .d.ts with, it can become a global type declaration.

So there's more than one way to approach this. Either you define your file as a module and thus have to import it specifically, or you avoid any imports / exports in the top level scope.

You can still do something like:

declare module '@api/event' {
  interface GetDriversResponse {
    driver: import("@api/event").Driver
  }
}

See the answer here for a more complete discussion

Nico
  • 872
  • 10
  • 16