Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

275
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!