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

276
Visualizações
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 à 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