This is mostly interesting as a template for using paths to prune the set of files considered by tsc when building a project.
Solution tsconfig.json:
{
"compilerOptions": {
"paths": {
"@pgtyped/query": [ "./declarations/pgtyped-query.d.ts" ],
"antlr4ts" : [ "./declarations/antlr4ts.d.ts" ],
"antlr4ts/RecognitionException": [ "./declarations/antlr4ts.d.ts" ]
}
}
}The contents of node_modules/@pgtyped/query/lib/index.d.ts as distributed on npm look like this:
export { getTypes, startup, IParseError } from './actions';
export { ParamTransform, IQueryParameters, IInterpolatedQuery, } from './preprocessor';
export { processTSQueryAST } from './preprocessor-ts';
export { processSQLQueryIR } from './preprocessor-sql';
export { AsyncQueue } from '@pgtyped/wire';
export { default as parseTypeScriptFile, TSQueryAST, } from './loader/typescript';
export { default as parseSQLFile, SQLQueryAST, SQLQueryIR, prettyPrintEvents, queryASTToIR, } from './loader/sql';
export { default as sql, TaggedQuery, PreparedQuery } from './tag';All I care about is the tag exports (sql and TaggedQuery). So I swapped in a version in declarations that only exports these (see other file in this gist).
Then I have a stub declarations file for the two antlr4ts modules that get imported by .d.ts files under tag.d.ts (also see attached).
The net result in my project is that antlr4ts is removed from the list of files considered by tsc.
Before
$ tsc --noEmit --listFiles | wc -l
3575
$ tsc --noEmit --listFiles | grep antlr4ts | wc -l
111After
$ tsc --noEmit --listFiles | wc -l
3456
$ tsc --noEmit --listFiles | grep antlr4ts | wc -l
1So 119 files removed from compilation, and the only remaining vestige of antlr4ts is my own declarations file. Hooray!