Mixing Type and Value Imports Efficiently
What you'll learn: How to combine import type and regular imports in a single statement to keep your code clean and concise.
The Scenario
You've learned that TypeScript offers import type for type-only imports and regular import for values. But what happens when you need both from the same module? You could write two separate import statements, but TypeScript gives you a better way.
Combining Them in One Statement
TypeScript allows you to mix type and value imports in a single import statement using inline type modifiers:
import { createUser, type User, type Role } from './user-service';
// createUser is a value (function) - available at runtime
const newUser = createUser('Alice');
// User and Role are types only - erased during compilation
const userData: User = { id: 1, name: 'Bob', role: 'admin' };
Notice the type keyword before specific imports (type User, type Role). This tells TypeScript and your bundler: "These are types only, the rest are values."
Why This Matters
Before (verbose):
import type { User, Role } from './user-service';
import { createUser } from './user-service';
After (efficient):
import { createUser, type User, type Role } from './user-service';
One line instead of two, clearer intent, and easier maintenance. Your bundler can still optimize away the type-only imports because they're explicitly marked with the inline type keyword.
Think of It Like Shopping
Imagine ordering from a restaurant: some items you'll eat now (values), some are just for the menu reference (types). Instead of making two separate orders, you mark certain items as "just for reference" on a single order form. More efficient, same result.
Key Takeaway: Use inline type modifiers within a single import statement (import { value, type Type }) to cleanly separate types from values without creating multiple import lines for the same module.