A TypeScript declaration file (.d.ts) contains type declarations without implementation code. It describes JavaScript or TypeScript APIs so TypeScript can apply static checking and tooling to code it cannot inspect as TypeScript source. section 3.9
Declaration files bridge JavaScript libraries and TypeScript projects by providing:
- Static type checking for untyped JavaScript code. section 3.9
- IntelliSense, autocompletion, and refactoring support in development tools. section 3.9
- Seamless integration of external npm modules into TypeScript projects. section 3.9
Interview-ready trade-off
A JavaScript npm package can ship a .d.ts file so consumers receive type safety and IDE support without receiving TypeScript source. This reduces package size and improves compatibility, but declarations must remain synchronized with the implementation. section 3.9

