Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

386
Vistas
TypeScript: Cannot import a type from a separate file in local dependency?

I have two local packages, package1 and package2, and I want to use a TypeScript type Car declared in a separate file in and exported from package1 in package2.

The structure of package1 is:

package1/
  src/
    index.ts
    car.d.ts
  lib/
    index.d.ts // generated
  tsconfig.json
  package.json

index.ts from package1 has only a single line:

export {Car} from './car';

So it's just re-exporting the type declared in car.d.ts, which may be something like

export interface Car {
  brand: string;
};

Now I want to use local package package1 in local package package2. After running

npm i local/path/to/package1

I get the following structure for package2:

package2/
  src/
    index.ts
  lib/
  node_modules/
    package1/  // link to other package
  tsconfig.json
  packjage.json

Everything ok so far. index.ts from package2 now tries to import Car:

import {Car} from './package1';

But that does not work; more precisely, Car is suddenly interpreted as a synonym to any (so typing does not work)! Even worse, I cannot compile package2 because applying tsc to it gives me: "error TS2307: Cannot find module './car' or its corresponding type declarations."

My tsconfig.json for both packages is the following:

{
  "compilerOptions": {
    "target": "es2016",
    "module": "commonjs",
    "declaration": true,
    "strict": true,

    "removeComments": false,

    "sourceMap": true,
    "declarationMap": true,

    "downlevelIteration": true,
    "esModuleInterop": true,

    "rootDir": "./src",
    "outDir": "./lib"
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules", "**/*.spec.ts"]
}
over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda