Skip to content
Tutorials Center
My learning

Topics

TypeScript Reference ยท Keywords and Declarations

The export type declaration

Reference for TypeScript export type and export type *: re-export types without runtime code, isolatedModules rules and the difference from export interface.

export type { A } exports names that exist only as types, and export type { A } from "m" re-exports them from another module. The statement is erased from the JavaScript output, so it never pulls in the source module.

This matters when a compiler works on one file at a time. If you write export { User } from "./user" and User is an interface, such a tool cannot know it has no runtime value, and the emitted re-export fails. export type states the fact so any tool can drop it safely. It is different from export type Alias = ..., which simply declares a type alias and exports it.

TypeScript
export type { User } from "./user.js";
export type * from "./models.js";
export type * as Models from "./models.js";

Try it

TypeScript Exporting types and values side by side

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

TypeScript Declaring and exporting in one step

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

Syntax

TypeScript
export type { A, B as C };
export type { A } from "m";
export type * from "m";
export type * as ns from "m";
export { type A, value } from "m";
export type Alias = string;
export interface I {}
Form Description
export type { A } Exports existing local names as type-only. They can be used only in type positions by importers.
export type { A } from "m" Re-exports names from a module as type-only.
export type * from "m" Re-exports everything as type-only (TypeScript 5.0 and later).
export type * as ns from "m" Re-exports the module namespace as a type-only name.
{ type A } A single type-only specifier inside an ordinary export list.

Edge cases and errors:

  • Importers cannot use a type-only export as a value, even when it is a class: new Box() fails with a message that the name was exported using export type.
  • Under isolatedModules, re-exporting a type without type is error TS1205.
  • export type does not change anything about checking inside the declaring file; the class can still be constructed there.
  • export type * from does not re-export a default.

Usage notes

  • Use export type in barrel files that re-export interfaces so a bundler or transpiler can drop them.
  • It is purely a declaration of intent; there is no runtime cost or effect.
  • For a type alias or interface declared right there, export type Alias or export interface is enough; no extra form is needed.
  • With verbatimModuleSyntax, export { Foo } from "./foo" is kept exactly as written, so a type there must have the modifier.
  • Making a class type-only on export is a deliberate way to stop consumers from constructing it.