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

Mixed Imports: Types and Values

Combining type and value imports in a single statement with import { type ... } syntax.

Mixed Imports: Types and Values

What you'll learn: How to import both types and runtime values from the same module in a single, clean import statement.

The Common Scenario

You've learned about import type for type-only imports that get erased at runtime. But in real code, you often need both types and actual values from the same module — like a class and its type, or a function and the type of its parameters.

Combining Type and Value Imports

TypeScript lets you mix type-only and value imports in a single statement using the type keyword inside the import braces:

import { type MyType, myFunction } from './module';

Here, MyType is imported as type-only (erased at compile time), while myFunction is a real runtime value. The type prefix applies only to that specific import.

Why This Matters

This syntax gives you precision without clutter:

  • Bundler efficiency: Clearly marks what's type-only, enabling better tree-shaking
  • Readability: One import line instead of two separate statements
  • Flexibility: Mix as many types and values as needed in one declaration

Example Pattern

// Instead of this:
import type { User } from './types';
import { fetchUser } from './api';

// You can write:
import { type User, fetchUser } from './api';

Both User and fetchUser come from the same module, but TypeScript knows User vanishes after compilation while fetchUser remains in your JavaScript output.

Key Takeaway: Use import { type TypeName, valueName } to cleanly combine type-only and runtime imports from the same module, giving bundlers clear signals while keeping your code concise.