Declaration Files
Declaration files end with .d.ts.
They describe types for JavaScript that has no types of its own.
Like a label on a gift box that was wrapped without a note.
They let TypeScript understand libraries and global variables.
Where types come from
Many packages ship their own .d.ts next to the JS.
A package is a ready made pile of code from npm.
DefinitelyTyped publishes @types/package-name for others.
You can also write your own ambient declarations.
Ambient means describe something that already exists at runtime.
A simple ambient function
In a .d.ts file, declare describes something that exists at runtime elsewhere.
Runtime means while the program is running.
The declaration adds name tags. It does not create the function.
Declaring a module
When TypeScript does not understand an import, declare the module.
Then imports stop erroring.
Start loose. Then tighten the exports.
Tighten means add more exact types over time.
Global augmentation
Augmentation means adding to an existing type.
Extend existing globals like Window when a script adds properties.
Keep those additions in dedicated .d.ts files so they stay easy to find.
allowJs and checkJs
You can type-check JavaScript files gradually.
Gradually means a little at a time.
allowJs lets .js files join the project.
checkJs turns on checking inside those files.
That helps migrate without writing .d.ts for everything first.
You finished the TypeScript course! Keep building with strict mode and real types.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.