Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Declaration Merging & Ambient De | TypeScript Mastery lesson | BraveProgrammer
  1. Courses
  2. /
  3. TypeScript Mastery

Lesson 22 of 56

·Typescript

Declaration Merging & Ambient Declarations

20 minutes

Course progress39%

Declaration Merging

When you declare the same identifier multiple times, TypeScript merges the definitions.

interface Window { foo: string; }
interface Window { bar: number; }
// Window now has both foo and bar

Merging Functions

function combine(a: string, b: string): string;
function combine(a: number, b: number): number;
function combine(a: any, b: any) {
  return a + b;
}

Ambient Declarations (declare)

Declare the shape of a value provided by external script or library.

// globals.d.ts
declare const $: (selector: string) => any;

Now you can use $ without TypeScript complaining.

Module Augmentation

// myLib.d.ts (external)
declare module "my-lib" { export function foo(): void; }
// augmentation
import "my-lib";
declare module "my-lib" { export function bar(): number; }

Info

Use declaration merging for extending third‑party types (e.g., adding a property to Express.Request).
Make it stickPractice what you've learned1 quiz · 3 practical tests · Optional activities from TypeScript MasteryBrowse activities
Previous lessonModules – ES6 Imports/Exports & NamespacesContinue to lesson 23Working with JSON & External APIsBack to TypeScript Mastery curriculum