Declaration regression tests
Concept and boundary
Generate declarations from a library source, then compile a separate consumer against the resulting declaration surface. For a small local project, a composite reference can enforce this separation and reveal a widened public return. A successful library build alone is insufficient.
Accepted project
Create a fresh folder with exactly these files. Use TypeScript 5.8.3 and Node.js 22.16.0. Package stubs under node_modules are local teaching fixtures, not installed dependencies.
app/tsconfig.json
{ "compilerOptions": { "composite": true, "strict": true, "types": [], "rootDir": ".", "outDir": "../dist/app" }, "files": [ "index.ts" ], "references": [ { "path": "../lib" } ]}lib/tsconfig.json
{ "compilerOptions": { "composite": true, "strict": true, "declaration": true, "types": [], "rootDir": ".", "outDir": "../dist/lib" }, "files": [ "index.ts" ]}tsconfig.json
{ "compilerOptions": { "strict": true, "target": "ES2022", "module": "CommonJS", "moduleResolution": "Node10", "moduleDetection": "force", "skipLibCheck": true, "noEmitOnError": true, "types": [] }, "include": [ "**/*" ], "exclude": [ "node_modules", "dist", "build", "cache" ], "files": [], "references": [ { "path": "./app" } ]}From the project root run: tsc -b tsconfig.json --pretty false.
Compilation succeeds (exit 0).
No runtime execution is required for this check.
dist/lib/index.d.ts exists.
Contains "n: number".
Rejected project — diagnosis
Intentionally rejected variant. Do not execute it.
Use a fresh copy of the accepted project, changing only the files shown below.
From the project root run: tsc -b tsconfig.json --pretty false.
Expected compiler diagnostic: TS2322
No runtime execution is required for this check.
The changed declaration exposes a string result to a numeric consumer. Restore the accepted configuration/source to compare the result.
Practice and recap
Add a second consumer that accepts the changed return type.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Declaration regression tests — knowledge check
Check the concept, interpret the tested project result, and diagnose a rejected configuration or source.
Which statement correctly describes Declaration regression tests?
Using the complete accepted project and the exact command in the lesson, which result is expected?
Why does the rejected project fail under its stated configuration?