Ambient declarations describe types for code you don't own. Useful for JS libraries, globals, or virtual modules. • declare module "lib": add typings for an untyped package • declare global: augment globalThis/window • declaration merging: extend existing module types
declare module "uuid" {
export function v4(): string;
}// ambient.d.ts
declare module "uuid" {
export function v4(): string;
}
declare global {
interface Window {
appVersion: string;
}
}
declare const process: {
env: { NODE_ENV: "development" | "production" };
};Understanding Ambient & Declaration Merging is fundamental to mastering TypeScript. Practice with the examples above and experiment with variations to solidify your knowledge.