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

277
Vistas
Jest test files not resolving TypeScript declaration file types

I have the following directory structure:

├── package.json
├── src
│   ├── @types
│   │   ├── foo.d.ts
│   ├── index.ts
│   ├── file1.ts
│   └── file2.ts
├── tests
│   └── foo.test.ts
├── tsconfig.json
├── jest.config.js
└── webpack.config.js

Here's an example of how foo.d.ts might look like:

type Level = "INFO" | "WARNING" | "ERROR" | "FATAL";

type ErrorReport = {
  id: string;
  message: string;
  level: Level;
};

My tsconfig.json file looks like this:

{
  "compilerOptions": {
    "noImplicitAny": true,
    "module": "es6",
    "target": "es5",
    "strict": true,
    "strictPropertyInitialization": false,
    "moduleResolution": "node"
  },
  "exclude": ["tests"]
}

Files in my src directory correctly find and make use of the type declarations I defined , without me explicitly importing the definition files.

//index.ts

const level: Level = "INFO"; //<- Level type correctly inferred from @types/foo.d.ts

However, files in the test directory do not resolve types correctly.

//foo.test.ts

const level: Level = "INFO"; //<- Error: Cannot find name 'Level'

Since my declaration files are not modules I cannot import them explicitly either. The corresponding Jest test suites are executed without errors BTW.

How may I get around this problem?

about 4 years ago · Juan Pablo Isaza
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