I'm trying to improve my tsc build times and editor responsiveness by reducing the number of source files that TypeScript pulls in. I'm seeing lots of .d.ts files in node_modules that are being pulled in via transitive dependencies, and I'd like a way to exclude them from consideration during compilation.
To make this more concrete: I'm using PgTyped to generate TypeScript type declarations for my SQL queries. To use it, I need to install two dependencies:
npm install @pgtyped/query @pgtyped/cli
The @pgtyped/query package depends on antlr4ts, which ships with many bundled .d.ts files of its own. These get pulled into my node_modules directory:
$ ls node_modules/antlr4ts/**/*.d.ts | wc -l
179
Some of these types do get pulled in via node_modules/@pgtyped/query/lib/index.d.ts. I can see this by using tsc --listFiles:
$ tsc --noEmit --listFiles | grep antlr4ts
/myrepo/ts/node_modules/antlr4ts/atn/ATNStateType.d.ts
/myrepo/ts/node_modules/antlr4ts/misc/Stubs.d.ts
/myrepo/ts/node_modules/antlr4ts/misc/IntegerList.d.ts
/myrepo/ts/node_modules/antlr4ts/misc/Interval.d.ts
...
So far as I can tell (famous last words!) these are all irrelevant to the public API of PgTyped. If I just replaced them with any, there would be no observable difference to my app and there would be ~100 fewer files that tsc would need to load.
I've tried a few techniques suggested on the TypeScript Wiki's Performance Page, namely including **/node_modules in my exclude:
{
"compilerOptions": {
"lib": [ "dom", "DOM.Iterable", "es2019" ],
"strict": true /* Enable all strict type-checking options. */,
"skipLibCheck": true,
// ... many other settings ...
},
"exclude": [
"./cypress",
"**/node_modules",
"**/.*/"
]
}
I've set skipLibCheck and also tried creating a declaration file to stub out antlr4ts:
// declarations/antlr4ts.d.ts
declare module 'antlr4ts';
This file shows up in the output of tsc --listFiles, but only after all 110 of the antlr4ts declarations files.
Is it possible to prevent TypeScript from seeing any of these .d.ts files? Ideally I'd like to have it give all of these antlr4ts modules an any type.