Skip to content
Tutorials Center
My learning

Topics

TypeScript Reference ยท Keywords and Declarations

The import type declaration

Reference for TypeScript import type and inline type modifiers: erased imports, import() types, verbatimModuleSyntax, and when type-only imports matter.

import type imports a name that can be used only in type positions. The whole statement is erased from the JavaScript output, so it can never trigger a module load, create a circular dependency at runtime or keep a large module in your bundle.

The same idea is available per name with an inline modifier, import { type A, b } from "m". In that form the statement stays when it also imports values, but A is dropped. Type-only imports make intent explicit and are required under verbatimModuleSyntax for anything that is purely a type.

TypeScript
import type { Server } from "node:http";
import { createServer, type IncomingMessage } from "node:http";

Try it

TypeScript Type-only and inline type imports

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 import() types and typeof

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
import type Default from "m";
import type { A, B as C } from "m";
import type * as NS from "m";
import { type A, value } from "m";
type T = import("m").Exported;
type Whole = typeof import("m");
Form Description
import type X Imports only for use in types. Using X as a value is an error.
import type * as NS A namespace usable in type positions, including typeof NS.value.
{ type A } Marks one specifier as type-only inside a normal import.
import("m").T An import type: refers to a type of a module without an import statement.

Edge cases and errors:

  • Using a type-only import as a value, such as new X() for an imported class, is error TS1361.
  • A class imported with import type can still be used in annotations, but not with new, instanceof or extends in expressions.
  • With verbatimModuleSyntax, import { A } from "m" where A is only a type is an error asking you to add type.
  • A statement made only of inline type modifiers, import { type A } from "m", is kept as import {} from "m" under verbatimModuleSyntax (a side-effect import), but fully erased with import type { A }.

Usage notes

  • Use import type when a module is needed only for annotations. It prevents accidental runtime cycles.
  • importsNotUsedAsValues and preserveValueImports were replaced by verbatimModuleSyntax; use that in new projects.
  • Transpilers that process one file at a time (esbuild, swc, Babel, Node's type stripping) cannot tell types from values across files, so import type is how you tell them what to drop.
  • Decorators with emitDecoratorMetadata can need the value import for metadata. A type-only import can break them.
  • import type does not change type checking. It only changes emit and enforces your intent.