Yashotantra Academy logo
← TypeScript theorytheory 0/50 · 0%
level 1
Curious · 0 XP
streak
0d
perfect
0
badges
0

100 XP to Apprentice

Tooling · medium

32. Module augmentation & declaration files

Describing the shape of untyped JS and extending existing types.

1 min read3 questionsup to 50 XPtopic 32/50

Read in another language

AI translates the explanation and quiz text while preserving code and answer scoring.

A `.d.ts` file contains only type declarations, no runtime code. It's used to describe the shape of plain JavaScript libraries, or to add global types to a project.

ts
// globals.d.ts
declare global {
  interface Window {
    ethereum?: { request: (args: { method: string }) => Promise<unknown> };
  }
}
export {};

Module augmentation lets you add to an existing module's types without modifying its source, e.g. extending a third-party library's interface with an extra field your app relies on. Many npm packages ship their own `.d.ts` (or point to `@types/<package>` on DefinitelyTyped) so consumers get type checking without the library itself being written in TypeScript.

How to study this topic

  1. 1. Read the explanation once end to end, skipping the code.
  2. 2. Re-read the code snippets and say out loud what each line does.
  3. 3. Answer the quiz without scrolling back — that is the real check.
  4. 4. Read every explanation, even for the answers you got right.

Scoring

  • · Up to 30 XP from quiz accuracy.
  • · +15 XP for a perfect first attempt.
  • · +5 XP while a 3-day streak is running.
  • · 75% or higher marks the topic complete.

Check your understanding

  1. 1. What does a `.d.ts` file contain?

  2. 2. What is 'module augmentation' used for?

  3. 3. Where do many untyped JS packages get their type definitions from?

Badges

First light
Pass your first topic
Sharp shooter
3 perfect first-try quizzes
On a roll
Study 3 days in a row
Week warrior
Study 7 days in a row
Grinder
Earn 500 XP
Deep diver
Earn 1500 XP