Lesson 3.1

Declaration files and module augmentation

A declaration file carries types with no implementation.

4mIntermediate16.3k students

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

Previous Lesson
Next Lesson
Declaration files and module augmentation — TypeScript Deep Dive — Vertex