Course contentsShow
← TypeScript
Lesson 1142 of 1,79627. Declaration FilesFree lesson

Export and Import in .d.ts

Declaration files can export types and interfaces just like regular modules using export statements.

Export and Import in .d.ts

What you'll learn: How declaration files use export and import statements just like regular TypeScript modules to share type definitions across files.

The Core Idea

Declaration files aren't isolated type islands—they participate in the module system just like your regular TypeScript files. When you define types, interfaces, classes, or functions in a .d.ts file, you can export them to make them available to other modules, and you can import types from other declaration files when you need them.

This means declaration files follow the same module patterns you already know: named exports, default exports, re-exports, and imports all work the same way.

How It Works

In a declaration file, you export type definitions using the familiar export keyword:

// types.d.ts
export interface User {
  id: number;
  name: string;
}

export type Status = "active" | "inactive";

export declare function greet(name: string): void;

Other files can then import these declarations:

// app.ts
import { User, Status } from './types';

const user: User = { id: 1, name: "Alice" };
const status: Status = "active";

You can also import types within declaration files when building on other type definitions:

// models.d.ts
import { User } from './types';

export interface Admin extends User {
  permissions: string[];
}

Think of It Like This

If regular TypeScript modules are containers that ship both blueprints (types) and machinery (runtime code), then declaration files are containers that ship only blueprints. The export and import syntax works identically—you're just packaging and sharing type information instead of executable code.

Key Takeaway: Declaration files use standard export and import statements to share type definitions across modules, participating in the same module system as regular TypeScript files.