Course contentsShow
← TypeScript
Lesson 1095 of 1,79626. Modules in TypeScriptFree lesson

Type-only import syntax with import type

Use import type { Type } to explicitly mark imports that won't exist at runtime.

Type-only import syntax with import type

You'll learn how to explicitly tell TypeScript which imports exist only for type-checking and won't appear in your compiled JavaScript.

What this solves

When you import types from other modules, they might get bundled into your JavaScript output even though they're only used for type-checking. TypeScript's import type syntax makes it crystal clear: "This import is purely for types—remove it entirely at runtime."

The core idea

The import type syntax looks almost identical to regular imports, but with one key difference:

// Regular import (could be a value or a type)
import { User } from './types';

// Type-only import (guaranteed to be removed)
import type { User } from './types';

When TypeScript compiles code with import type, it guarantees that import statement won't exist in the emitted JavaScript. It's purely for the type-checker's benefit.

Why this matters

Clarity for humans and tools: When you use import type, you're making an explicit contract: "This is never used as a runtime value." This helps bundlers tree-shake more aggressively and makes your intent obvious to other developers.

Prevents accidental runtime usage: If you try to use a type-only import as a value, TypeScript will immediately error. This catches mistakes where you might accidentally reference something that won't exist at runtime.

Works with isolatedModules: Build tools like Babel that compile files independently can safely strip type-only imports without analyzing the entire dependency graph.

When to use it

Use import type when importing interfaces, type aliases, or anything you'll only reference in type annotations—never as a runtime value.

Key Takeaway: import type { Type } explicitly marks imports that exist only for type-checking, ensuring they're completely removed from your compiled JavaScript and preventing accidental runtime usage.