Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

TypeScript type export is the module system mechanism used to expose static type declarations—such as interfaces, type aliases, and type signatures—from a file, allowing them to be imported and consumed by other modules. Because TypeScript utilizes type erasure, these exported constructs exist exclusively at compile-time and are entirely stripped from the emitted JavaScript code.

Inline Type Exports

Types and interfaces can be exported directly at the point of declaration using the export keyword.
export type UUID = string;

export interface Entity {
  id: UUID;
  createdAt: Date;
}

Default Exports

TypeScript supports default exports for types, but enforces a strict syntactic distinction between interfaces and type aliases. While interfaces can be exported as defaults inline, type aliases cannot and will result in a syntax error. They must be split into a declaration and a subsequent export statement.
// Valid: Inline default export for an interface
export default interface Config {
  retries: number;
}

// Syntax Error: Cannot use inline default export for a type alias
// export default type Status = 'pending' | 'resolved';

// Valid: Split declaration and default export for a type alias
type Status = 'pending' | 'resolved';
export default Status;

Export Blocks

Types can be declared locally within a module and exported collectively at the end of the file.
type Status = 'pending' | 'resolved';
interface Task {
  status: Status;
}

export { Status, Task };

Type-Only Exports (export type)

TypeScript provides the export type modifier to explicitly denote that the exported members are strictly compile-time types. This guarantees to the compiler and external transpilers (like Babel, SWC, or esbuild) that the export contains no runtime values.
interface Entity {
  id: string;
}

interface Task {
  title: string;
}

// Exports all members as types
export type { Entity, Task };
As of TypeScript 4.5, you can mix value and type exports within a single export block using inline type modifiers.
interface Task {
  title: string;
  status: string;
}

const defaultTask: Task = { title: 'New Task', status: 'pending' };

// 'defaultTask' is a runtime value, 'Task' is a compile-time type
export { defaultTask, type Task };

Re-exporting Types

Modules can re-export types originating from other modules. TypeScript provides specific syntax to differentiate between re-exporting values, types, or both.
// Re-exporting specific types
export type { UUID, Entity } from './entity';

// Re-exports BOTH values and types from a module
export * from './task';

// Re-exports ONLY types from a module (TypeScript 5.0+)
export type * from './task';

// Re-exporting with inline type modifiers
export { defaultTask, type Task } from './task';

Compiler Mechanics and Flags

The behavior of type exports is heavily influenced by TypeScript compiler options, specifically regarding single-file transpilation:
  • Type Erasure: During the emit phase, tsc removes all type declarations and type-only exports. If a module only exports types, the entire export statement is omitted from the resulting .js file.
  • isolatedModules: When enabled, transpilers operate on a single file at a time without cross-file type-checker context. Local type exports (e.g., type T = string; export { T };) are valid because the transpiler can infer the type from the local declaration. However, re-exports (e.g., export { T } from './module';) are ambiguous because the transpiler cannot inspect the external file to determine if T is a value or a type. Explicit export type modifiers are required for these re-exports to ensure the transpiler safely erases them.
  • verbatimModuleSyntax: When enabled in tsconfig.json, TypeScript enforces strict adherence to explicit type modifiers. Any export that is only used as a type must be exported using export type, ensuring predictable and safe module emit across all build tools.
Master TypeScript with Deep Grasping Methodology!Learn More