I have a monorepo project which consist of 3 packages. Monorepo structure looks like this:
- packages/
- common/
- types.ts
- ComponentA/
- ComponentB/
As you can see, in common package I have one file which contains all types (some of them are shared) for both components.
When I'm building e.g. ComponentA using Babel and Webpack, at the end all types are emitted in one single file main.d.ts which look like this:
declare module "common/types" {
export type Foo = {
width: number;
height: number;
};
}
declare module "ComponentA/src/main" {
export * from "common/types";
}
...
In in main.js file of ComponentA I'm also exporting all types and types are specified in package.json
{
"name": "ComponentA",
"version": "1.0.0",
"main": "dist/main.js",
"types": "dist/main.d.ts",
"license": "MIT",
"files": [
"dist/*"
],
...
}
Problem is, that when I wanna use types of ComponentA (e.g. type Foo) in another typescript based project, types are recognized in two modules like this:
import 'Foo' from 'common/types'
and
import 'Foo' from 'ComponentA/src/main'
I know that type Foo is declared in common/module in generated main.d.ts file but naming 'common/types` doesn't make much sense. How can I improve this? Thanks