Skip to main content
Module 7 · Lesson 2 of 214/22 in the course~16 min
Module lessons (2/2)

Declarations and Merging

Lesson preview5 hands-on exercises readyCourse TypeScript · Module 7 — Configuration and Integration

Write ambient declarations (.d.ts), augment existing modules and manage JS interoperability.

What you'll learn in this lesson

  • Understand the role of .d.ts declaration files to provide types to JavaScript libraries as well.
  • Take advantage of Declaration Merging between interface blocks with the same name in the same scope.
  • Extend global types (declare global { interface Window { ... } }) without resorting to casting as any.
  • Run Module Augmentation (declare module 'nome-pacchetto') to add typed fields to external libraries (plugins, HTTP requests).

Overview

TypeScript lives in a huge ecosystem also made up of existing JavaScript libraries and global variables injected from the environment. The declaration files (.d.ts) and the declare keyword describe shapes that already exist at runtime without generating any extra JavaScript code.

Two interface declarations with the same name in the same form automatically merge into a single contract containing all fields (unlike type, which generates duplicate identifier error!).

Sections covered in this lesson

  1. 1Declaration Merging between Interfaces
  2. 2Ambient Declarations & declare global
  3. 3File .d.ts and Module Augmentation
  4. 4Guided practice
  5. 5Check for understanding
Pro Lesson · Module 7 — Configuration and Integration

Unlock "Declarations and Merging" and the full Course TypeScript curriculum

Write ambient declarations (.d.ts), augment existing modules and manage JS interoperability.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Course TypeScript plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.