ambient declaration
A declaration starting with declare, which tells the compiler something exists at run time without generating any code for it.
In more detail
declare const VERSION: string describes a global set by a script tag or build tool. Ambient declarations produce no output, so a wrong one is a lie the compiler will believe.
Related terms
- declaration file — A file ending in .d.ts that contains only type information describing JavaScript that exists elsewhere, with no runnable code.
- global augmentation — Adding types to global objects such as Window or NodeJS.ProcessEnv with a declare global { } block inside a module.
- module augmentation — Adding types to another package from your own code with declare module "name" { } and declaration merging.
Taught in
- Why TypeScript: Contracts, Erased Types And Soundness — Production TypeScript
- The Compiler Pipeline: tsc, AST And Code Emission — Production TypeScript
- tsconfig.json: target, lib, strict And NodeNext — Production TypeScript
- Type Annotations, Type Inference And Contextual Typing — Production TypeScript
- Primitive Types: String, Number, Boolean, Bigint And Symbol — Production TypeScript
- Literal Types: String, Number, Boolean Literals And const — Production TypeScript
- never: The Bottom Type And Exhaustive Switch Checking — Production TypeScript
- Type Aliases Versus Interfaces: Declaration Merging — Production TypeScript
- Optional Properties, Readonly And Index Signatures — Production TypeScript
- Union Types, Intersections And Property Conflicts — Production TypeScript
- Discriminated Unions: Tagged Variants And Pattern Matching — Production TypeScript
- Tuples: Fixed Length, Labeled Elements And Variadic Tuples — Production TypeScript
- The in Operator And Instanceof Narrowing — Production TypeScript
- Why Generics: Functions, Identities And Type Variables — Production TypeScript
- Default Generic Arguments And Multi-Type Parameters — Production TypeScript
- Core Utilities: Partial, Required, Readonly, Pick And Omit — Production TypeScript
- Union Utilities: Exclude, Extract, NonNullable And Awaited — Production TypeScript
- Function Utilities: ReturnType, Parameters And Constructor — Production TypeScript
- Conditional Types: Ternary Types And Type Inference With infer — Production TypeScript
- Mapped Types, Key Remapping With as And Template Literals — Production TypeScript
- ECMAScript Modules, CJS Interop And verbatimModuleSyntax — Production TypeScript
- Declaration Files, Ambient Namespaces And Module Augmentation — Production TypeScript
- The satisfies Operator: Safe Validation Without Widening — Production TypeScript
- Modern Decorators: Stage 3 Standards And Class Metadata — Production TypeScript
- The Spine Artifact: Generating Typed Models From OpenAPI — Production TypeScript