Question presented to candidate:
"What is a .d.ts file? Where do they come from, how does TypeScript find the types for a package you install, and what happens when a declaration file is wrong?"
What a strong answer should cover:
- A
.d.tsfile contains only types (ambient declarations): it describes JavaScript that exists elsewhere and produces no output of its own - Where they come from: generated by
tsc --declarationfrom your own.ts, shipped by a package ("types"inpackage.json), published to@types/*from DefinitelyTyped, or written by hand (globals,declare module "*.svg") - What happens with none: under
strict(noImplicitAny), importing an untyped JavaScript package is error TS7016 - Declarations are trusted, not checked against the JavaScript: a wrong
.d.tscompiles and crashes at run time skipLibCheckskips type-checking.d.tsfiles: faster builds, but a broken declaration then silently degrades toany- Script vs module
.d.ts: a file with top-levelimport/exportis a module; global declarations and wildcarddeclare modulepatterns belong in a script file (ordeclare global)
Code / implementation expected: Optional β the .d.ts that tsc --declaration emits for a small module, or a hand-written declaration for an untyped package.