Type-Only Imports with Side Effects
What you'll learn: How type-only imports eliminate side effects and when regular imports are still needed.
The Core Problem
When you use import type, TypeScript completely removes that import at compile time. This is usually what you want for types, but sometimes a module needs to run side effects on import — like registering plugins, polyfills, or global augmentations.
If you use import type for a module that has side effects, those effects never happen because the import disappears entirely.
Type-Only Imports = Zero Runtime Code
// polyfills.ts
globalThis.myPolyfill = () => { /* ... */ };
// main.ts - WRONG
import type { SomeType } from './polyfills';
// ❌ The polyfill never runs! Import is erased.
The compiled JavaScript will have no import at all — polyfills.ts never executes.
When You Need Regular Imports
Use a regular import when the module must execute:
// Correct: side effect preserved
import './polyfills'; // ✅ Runs the module
import type { SomeType } from './polyfills'; // Just the type
Or mix them in one statement:
import polyfills, { type SomeType } from './polyfills';
// Value imported (side effects run), type imported separately
Real-World Scenarios
Plugin registration systems, CSS imports, global type augmentations all need regular imports to execute. Use import type only when you're certain you need just the type information.
Key Takeaway: Type-only imports vanish at runtime, eliminating side effects — use regular imports when module execution is required, and reserve import type for purely type-level dependencies.