When developing in ES6 style module inclusion within WebStorm, I encountered an issue with my Express app and a custom d.ts file. The d.ts file contains middleware that alters objects, and the structure looks like this:
declare module Express {
export interface Application {
getLogger(): LoggerInstance;
getRepository(collectionName): IRepository;
getEnvironmentVars(): any;
}
}
The IDE does not show any errors when using these declarations, but when I run the code through TSC, it throws an error saying
'getRepository' does not exist on type 'Application'
.
I have other d.ts files that work fine without any issues, so it's puzzling why this specific one is causing problems.
An example scenario of how the d.ts file is used:
import { Express } from "express"
export function SomeMiddleWare(app: Express){...};
In this case, Express in express.d.ts extends Application, which includes the augmentations defined in the problematic d.ts file.
I'm confused as to why it functions correctly in the IDE but fails in TSC. TSC includes all *.d.ts files within a typing directory, and no errors are reported in those files – only in the specific d.ts file where the issue lies.