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?