0

I need to export all of my type files from a single index.d.ts file. Let's say I have:

types/event.d.ts

interface EventJD {
  typeName: string;
  fieldName: string;
}

I then want to export all of the interfaces from event.d.ts (and any other files) from index.d.ts. I've tried the following, based on this answer

types/index.d.ts

export * from "./event.d.ts" // linter gives error for "./event.d.ts" An import path cannot end with a '.d.ts' extension. Consider importing './event' instead.

export * from "./event" // File '/.../types/event.d.ts' is not a module.ts(2306)
JimmyTheCode
  • 3,783
  • 7
  • 29
  • 71

1 Answers1

1

Problem is that if you do not export anything from types/event.d.ts then you get the file is not the module error. Only way I can think of to solve this is to export from type.d.ts.

After skimming the docs I don't see any other way.

Bojan Tomić
  • 1,007
  • 12
  • 19
  • Thanks for looking! I think the problem with adding an export to a `d.ts` file is that you then have to `import` the interfaces/types/etc. Correct me if I'm wrong, but I think this negates the benefit of having a `.d.ts` file, and so I might as well switch it to a `.ts` file? – JimmyTheCode Oct 07 '22 at 08:35
  • 1
    You are completely right. I use `.ts.` mostly and I import all my types, but then again I give slight edge to the `interfaces` since you can extend them. As far as I understood if you only use typescript there is no need for type declaration since your code is already strongly typed. Now if you would to have `.js` files and wanted to have type checking you would need a `d.ts` file along side in order for it to work. Here is a better explanation then I can provide [here](https://stackoverflow.com/a/21247316/5761648). – Bojan Tomić Oct 08 '22 at 11:05