TypeScript Advanced Declaration Authoring
Backward-compatible declaration evolution
An added optional trailing parameter preserves the illustrated existing call contract. Compare the same consumer against both versions instead of checking only a new usage. Compatibility here is limited to this call shape; overload ordering, assignability, behavioral changes and other consumers need their own tests. 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
export function read(value: number, optional?: number): number;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: node_modules/demo/package.json (omit this label){ "name": "demo", "version": "1.0.0", "main": "./index.cjs", "types": "./index.d.cts"}
// File: node_modules/demo/index.d.cts (omit this label)export function read(n: number): number;
// File: node_modules/demo/index.cjs (omit this label)exports.read = n => n;
// File: main.cts (omit this label)import { read } from "demo";const result: number = read(3);console.log(result);
// Run: tsc -p . --pretty false// Expected: no diagnostics.// Run: node main.cjs// Expected stdout: 3