Course contentsShow
← TypeScript
Lesson 1126 of 1,79626. Modules in TypeScriptFree lesson

Structure of a Basic Declaration File

Learning the anatomy of a .d.ts file with export declarations and type definitions.

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:

  1. Top-level exports - Declarations marked with export that other files can import
  2. Type definitions - Interfaces, type aliases, and other type constructs
  3. 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 interface declarations for object shapes
  • export type for type aliases
  • export function signatures (no implementation, just parameter and return types)
  • export const or export let for value declarations (type only, no initializer)
  • export class declarations 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.