typescript-docs-broken-cli-command
Root cause. The README instructed users to type-check a single file:
npx tsc --noEmit --skipLibCheck src/example.ts
This is broken in two ways, both verified against real tsc binaries:
tsconfig.json exists in the current directory, passing file names on the command line is an error — the config would be silently bypassed, so tsc refuses:
error TS5112: tsconfig.json is present but will not be loaded if files are specified on commandline.
Use '--ignoreConfig' to skip this error.
On TS 5.x the same command exits 0 but silently ignores tsconfig.json, so examples get checked against the wrong compiler options (no strict, no project types, no skipLibCheck tuning) — a latent false-negative.--ignoreConfig: the suggested escape hatch strips the project config, including "types": ["node"], so a CJS example using require.main === module fails even with @types/node installed:
error TS2591: Cannot find name 'require'. Do you need to install type definitions for node?
Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig.Fix (docs-only). Point the README at the project-wide invocation and state that examples are type-checked in the context of the project, not standalone.
README diff:
## Type-checking
-Run the compiler on a single example file:
+Run the compiler against the whole project from the repository root:
```bash
-npx tsc --noEmit --skipLibCheck src/example.ts
+npx tsc --noEmit
```
-The example compiles standalone, so `tsconfig.json` is ignored.
+This reads `tsconfig.json` (its `include`/`files` decide what is checked, and
+`strict`, `skipLibCheck`, and `types` come from the config). Do not pass
+individual file paths on the command line — TypeScript ≥ 6.0 rejects that
+combination with `TS5112`, and the `--ignoreConfig` workaround strips the
+project settings (e.g. `types: ["node"]`), which breaks CJS examples that use
+`require` with `TS2591`.
+
+Example snippets are part of the project and are checked in its context, not as
+standalone programs. In CI or a pre-commit hook, use the same command:
+
+```bash
+npx tsc --noEmit
+```
Key rules the corrected docs encode:
tsconfig.json lives.--project/existing config with explicit file arguments (that is exactly the TS5112/TS5110 class of error).npx tsc --noEmit --skipLibCheck is fine without file arguments; the config already carries the project's settings.require, module) belong under the tsconfig's include with @types/node installed and "types": ["node"] (or left unset so all @types/* are auto-included); they are not standalone-compilable.Verified empirically with a reproduction project (`src/cli.ts` using `require.main === module`, `tsconfig.json` with `"types": ["node"]`, `@types/node` + `typescript` installed) and real binaries:
| # | Command | TypeScript | Result |
|---|---------|-----------|--------|
| 1 | `npx tsc --noEmit` (fix, project-wide) | 7.0.2 | **exit 0** — clean pass |
| 2 | `npx tsc --noEmit --skipLibCheck src/cli.ts` (old docs) | 7.0.2 | **exit 1** — `TS5112` "tsconfig.json is present but will not be loaded if files are specified on commandline" |
| 3 | `npx tsc --noEmit --skipLibCheck src/cli.ts` (old docs) | 6.0.2 | **exit 1** — same `TS5112` |
| 4 | `npx tsc --noEmit --skipLibCheck src/cli.ts` (old docs) | 5.9.3 | **exit 0** — but silently ignored tsconfig (wrong options applied) |
| 5 | `npx tsc --noEmit --ignoreConfig src/cli.ts` (old fallback) | 7.0.2 | **exit 1** — `TS2591` ×2 ("Cannot find name 'require'", "'module'") because `types: ["node"]` was stripped |
| 6 | `npx tsc --noEmit --skipLibCheck` (no file args) | 7.0.2 | **exit 0** — flags remain legal as overrides |
| 7 | broken file added, `npx tsc --noEmit` | 7.0.2 | **exit 1** — `TS2322: Type 'string' is not assignable to type 'number'` (fix still catches real errors) |
| 8 | example importing a sibling module, `npx tsc --noEmit` | 7.0.2 | **exit 0** — project-context checking covers imports that standalone compilation never could |
Edge cases covered: tsconfig present vs. absent (absent = no TS5112, but the old one-file style still misses project options); `require`/`module` usage in CJS without node types (TS2591 is a *correct* error there — the fix is node types in the project, not `--ignoreConfig`); `--skipLibCheck`/other flags still usable as overrides; TS 5.x silent-ignore divergence vs. TS 6+/7.x hard error. Guard: docs-only change (no source edits), Exception 3 foreman-direct, guard PASS 4/4.{"model": "deepseek-v4-flash", "problem_class": "typescript-docs-broken-cli-command", "result": "passed", "tests": 4}