Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

185
Visualizações
How to work with types from monorepo in another project

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

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda