Type-only Export Syntax with export type
What you'll learn: How to explicitly mark exports as type-only using export type, making your module boundaries clearer and your compiled code cleaner.
What It Is
Just as you can use import type to import only types (never values), you can use export type to explicitly export only types from a module. This tells TypeScript — and anyone reading your code — that these exports exist purely at compile time and will never be JavaScript values at runtime.
// types.ts
export type User = {
id: number;
name: string;
};
export type Status = "active" | "inactive";
// This exports ONLY the type, never a value
export type { User as UserType };
Value vs Type Exports
TypeScript supports both values (functions, classes, objects) and types (interfaces, type aliases). Sometimes you export both:
// product.ts
export interface Product {
id: number;
name: string;
}
export const DEFAULT_PRODUCT: Product = {
id: 0,
name: "Unknown"
};
Here, Product is a type export and DEFAULT_PRODUCT is a value export. TypeScript can usually figure this out automatically, but using export type makes it explicit and intentional.
Why Use export type
Clarity: When you write export type, you're documenting that this export has no runtime presence. Readers immediately know it's compile-time only.
Build tool optimization: Tools like bundlers and compilers can safely strip these exports without worrying about side effects, potentially improving tree-shaking.
Avoid confusion: Prevents accidentally trying to use a type as if it were a value, especially when re-exporting from barrel files.
// config-types.ts
export type Config = {
apiUrl: string;
timeout: number;
};
// Re-exporting explicitly
export type { Config as AppConfig };
The Syntax Forms
You can use export type in multiple ways:
// Direct export
export type Point = { x: number; y: number };
// Named re-export
export type { User } from "./user";
// Renamed re-export
export type { User as UserModel } from "./user";
// Multiple type-only exports
export type { Product, Category, Tag } from "./catalog";
Key Takeaway: Use export type to explicitly mark exports as compile-time only, creating clearer module boundaries between types and runtime values.