TypeScript Advanced Declaration Authoring
Independent declaration consumer tests
Build the producer first, then compile a consumer that resolves only the installed output package. This checks package entry points and public signatures rather than accidentally importing internal source. Run the emitted consumer to check its selected runtime path. An invalid null argument must fail with strict null checking. Baseline: TypeScript 5.8.3, strict NodeNext consumer unless otherwise noted. Create the labeled files separately; do not paste this project into a single-file editor.
Formal Syntax & Structure
typescript syntaxtypescript
tsc -p producer && tsc -p .Working Example
Example Snippettypescript
// File: tsconfig.json (omit this label){ "compilerOptions": { "target": "ES2022", "module": "NodeNext", "moduleResolution": "NodeNext", "strict": true, "types": [], "lib": [ "ES2022", "DOM" ], "noEmitOnError": true }, "files": [ "main.cts" ]}
// File: producer/tsconfig.json (omit this label){ "compilerOptions": { "target": "ES2022", "module": "NodeNext", "strict": true, "types": [], "lib": [ "ES2022" ], "declaration": true, "outDir": "../node_modules/demo", "noEmitOnError": true }, "files": [ "index.cts" ]}
// File: producer/index.cts (omit this label)export function read(n: number): number { return n + 1; }
// File: node_modules/demo/package.json (omit this label){ "name": "demo", "main": "index.cjs", "types": "index.d.cts"}
// File: main.cts (omit this label)import { read } from "demo";console.log(read(4));
// Run: tsc -p producer --pretty false// Run: tsc -p . --pretty false// Expected: no diagnostics.// Run: node main.cjs// Expected stdout: 5