typescript-glob-override-plugin
v0.1.2
Published
TypeScript Language Service plugin: enable specific compiler options for files matching glob patterns
Maintainers
Readme
typescript-glob-override-plugin
TypeScript Language Service plugin that enables specific compiler options for files matching glob patterns — without changing the project-wide tsconfig.json.
Useful for incrementally introducing strict checks into a large codebase.
Install
npm install --save-dev typescript-glob-override-plugin
# or
yarn add -D typescript-glob-override-pluginSetup
Add the plugin to your tsconfig.json:
{
"compilerOptions": {
"plugins": [
{
"name": "typescript-glob-override-plugin",
"files": [
"a/**/*.ts",
"b/**/*.ts"
],
"compilerOptions": {
"noImplicitOverride": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noImplicitAny": true
}
}
]
}
}VS Code
Make sure VS Code uses the workspace TypeScript version (not the built-in one):
- Open the Command Palette (
Cmd+Shift+P) - Run TypeScript: Select TypeScript Version
- Choose Use Workspace Version
Or add to .vscode/settings.json:
{
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.preferences.allowLocalPluginLoads": true
}Configuration
| Field | Type | Required | Description |
|-------|------|----------|-------------|
| files | string[] | Yes | Glob patterns relative to the tsconfig.json directory. Files matching any pattern will have compilerOptions applied. |
| compilerOptions | object | Yes | Any valid TypeScript compiler options to overlay on matched files. Common values: noImplicitOverride, strictNullChecks, strictFunctionTypes, noImplicitAny, strict. |
Glob syntax
| Pattern | Matches |
|---------|---------|
| src/foo/**/*.ts | All .ts files anywhere under src/foo/ |
| src/**/*.ts | All .ts files anywhere under src/ |
| src/foo/*.ts | .ts files directly inside src/foo/ (not nested) |
| src/foo/bar.ts | Exactly src/foo/bar.ts |
CLI: tsc-override
The package ships a tsc-override command that enforces the glob-based rules at build time / in CI — as a single drop-in replacement for tsc.
# Check all files using tsconfig.json in the current directory
tsc-override
# Point at a specific tsconfig
tsc-override --project path/to/tsconfig.json
tsc-override -p path/to/tsconfig.jsontsc-override checks every file in the project in one pass, routing each to the correct compiler options:
| File | Options used | Errors reported |
|------|-------------|-----------------|
| Matches a files glob | base options + plugin compilerOptions | Yes |
| Does not match any glob | base options (original tsconfig.json) | Yes |
Both programs include all project files so cross-file type inference is correct. The override options never leak into non-matched files, which is important when the override is more lenient than the base (e.g. removing strictNullChecks for a transitional directory).
Exit codes: 0 (all files passed) or 1 (errors found, or a configuration error).
Example CI integration
# .github/workflows/typecheck.yml
- run: tsc-override # replaces tsc; also enforces per-glob overridesHow it works
The plugin creates a second TypeScript Language Service backed by a proxy LanguageServiceHost whose getCompilationSettings returns the original options merged with compilerOptions. When getSemanticDiagnostics (or getQuickInfoAtPosition) is called for a file that matches one of the files globs, the call is forwarded to this strict service instead of the original one.
The tsc-override CLI uses the same config and glob matching, but drives compilation via two ts.createProgram instances — one with base options (for non-matched files) and one with merged options (for matched files) — both including all project files for correct cross-file type inference. No subprocess is spawned.
Inspired by allegro/typescript-strict-plugin.
Caveats
strictNullChecksis contagious. Enabling it changes type inference for the whole program (including non-matched files), which may surface extra errors in strict files that import from non-matched ones.- First load is slow. The strict LanguageService builds its own Program on first use. For large projects this may take a few seconds; subsequent calls are fast.
License
MIT
