Declaration Files
- What .d.ts is. A declaration file carries types with no implementation: the compile-time face of published JavaScript.
- declare. The declare keyword describes something that exists at runtime elsewhere: globals, injected values, legacy scripts.
- Reading declarations. Jump-to-definition lands in .d.ts files constantly: reading them fluently is a working skill, not trivia.
Third-Party Type Definitions
- Bundled types. Most modern packages bundle their own types: install and the shapes arrive with the code.
- DefinitelyTyped. Untyped packages get community types from DefinitelyTyped, installed as @types/ packages.
- When types are wrong. Published types can lag reality: augment or locally patch them, and upstream the fix.
Publishing Typed Libraries
- Shipping declarations. A published library ships its .d.ts and points package.json’s types field at them.
- Semantic versioning of types. A narrowed parameter or widened return is a breaking change even when the JavaScript never moved.
- API extractor discipline. Review your public type surface on every release: an accidentally exported internal is instant legacy.
Before and after this level
- Before: Level 10: Async & External Data: Typed Promises and Async Code, API Response Types, Runtime Validation vs Compile-Time Types.
- Next: Level 12: Error Modelling: Typed Results and Errors, Exhaustiveness, Designing Impossible States Out.
In the app each of these ideas is taught and then asked back, and the level ends with a checkpoint and flashcards. See Checkpoints and flashcards.
Frequently asked questions
What does TypeScript Level 11: Libraries & Declarations cover?
Declaration Files, Third-Party Type Definitions, Publishing Typed Libraries: 3 lessons and 9 ideas.
What should I know before this level?
The level before it, Level 10: Async & External Data, which covers Typed Promises and Async Code, API Response Types, Runtime Validation vs Compile-Time Types.