- All Courses
- TypeScript Deep Dive
- Typing Real Codebases
- Declaration files and module augmentation
Declaration files and module augmentation
A declaration file carries types with no implementation.
Overview
Describing code you do not own
A declaration file carries types with no implementation. It is how you type a plain JavaScript dependency, and how community type packages work for libraries that ship none.
Module augmentation adds members to an existing module — a custom property on a framework request object, an extra field on a session. Because it is global and invisible at the use site, it should live in one obvious file rather than being scattered.
Ambient declarations are unchecked assertions. If the library changes, nothing tells you the declaration is now wrong except a runtime failure, so keep them minimal.
In this lesson you will:
- Type an untyped dependency
- Extend an existing module or global
- Keep ambient declarations under control
Resources
Notes are not saved yet — they clear when you leave this page.
infer and type-level pattern matching
19m
Typing async boundaries and API responses
36m