Structure of a Basic Declaration File
What you'll learn: The anatomy of a .d.ts file and how to organize export declarations and type definitions within it.
What Is a Declaration File Made Of?
A declaration file (.d.ts) is TypeScript's way of describing types that exist elsewhere—usually in JavaScript code. Think of it as a blueprint or schematic that explains the shape of values without containing the actual implementation.
The structure is remarkably straightforward: it's essentially a collection of export declarations that describe what types, interfaces, functions, and values are available from a module.
Basic Anatomy
Every declaration file follows this simple pattern:
- Top-level exports - Declarations marked with
exportthat other files can import - Type definitions - Interfaces, type aliases, and other type constructs
- Ambient declarations - Descriptions of values, functions, and classes that exist at runtime
The file contains no implementation code—only type information. You won't find function bodies or actual values, just their signatures and shapes.
Common Building Blocks
A typical .d.ts file includes:
export interfacedeclarations for object shapesexport typefor type aliasesexport functionsignatures (no implementation, just parameter and return types)export constorexport letfor value declarations (type only, no initializer)export classdeclarations with typed properties and methods (no method bodies)
You can also use export default just like in regular TypeScript files, and combine multiple exports together.
The Mental Model
Picture a declaration file as a table of contents for a JavaScript library. It tells TypeScript "here's what exists, here are their types" without actually creating those things. The runtime code lives elsewhere—the .d.ts file is purely for the type checker's benefit.
Key Takeaway: A declaration file is a structured collection of export statements describing types, functions, and values—containing signatures and shapes, but never implementation code.