intermediate
Declaration files and CI type checking
Publish or consume .d.ts files, manage ambient types, and keep type checking deterministic in CI.
Declaration files (`.d.ts`) describe JavaScript modules or published package APIs without implementation. They can be generated from TypeScript, written manually for JavaScript, or installed from DefinitelyTyped. CI type checking makes these contracts reproducible outside the editor.
Stale `.d.ts` files can promise APIs that runtime code does not provide. Broad ambient globals can mask missing imports.
{ "scripts": { "typecheck": "tsc --noEmit" } }
On interviews: explain with a concrete example and name what interviewers probe in production code.
Common pitfalls: mixing similar APIs and forgetting edge cases during live coding.
The trade-off is often clarity versus safety or expressiveness versus maintainability. Checklist:
- Generate declarations for packages.
- Keep d.ts tied to runtime API.
- Run typecheck in CI.