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

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. TypeScript Mastery

Lesson 22 of 56 · Typescript

Declaration Merging & Ambient Declarations

Duration: 20 minutes

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).

Previous: Modules – ES6 Imports/Exports & NamespacesNext: Working with JSON & External APIs