🔷 TypeScript Intermediate

What is the difference between import type and import in TypeScript?

Why Interviewers Ask This

Candidates at the intermediate level are expected to not only know this concept but explain the trade-offs involved. Interviewers use this question to see if you can reason about design decisions, not just recall facts.

Answer

import type (TypeScript 3.8+) imports only the type information from a module — it is guaranteed to be completely erased from the compiled JavaScript output, leaving no trace. Regular import may or may not be erased depending on whether the imported values are used as values (not just types). Why it matters: (1) Performance: type-only imports allow bundlers and compilers to more easily eliminate unused imports. (2) Circular references: type imports avoid runtime circular dependency issues, since they exist only at type-check time. (3) Clarity: signals to readers that this import is used only for typing, not for runtime behavior. (4) With "isolatedModules": true (required for Babel/SWC transpilation), TypeScript enforces that re-exported types use export type. Inline type imports (TS 4.5): import { type User, fetchUser } from "./api" — mix type and value imports in one statement. Best practice: use import type whenever importing only for typing purposes.

Common Mistake

Don't just define the term — demonstrate that you understand when to use it and when not to. Showing awareness of trade-offs is what separates average from strong TypeScript candidates.