A type import in TypeScript is a module resolution mechanism that allows developers to import type declarations—such as interfaces, type aliases, and type signatures—from an external module exclusively for static type checking. By explicitly designating an import as type-only, the TypeScript compiler guarantees that the import statement is completely erased during the transpilation phase, resulting in zero runtime JavaScript output.Documentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
Syntax
TypeScript supports two syntactical forms for type imports: 1. Top-Level Type Import (TypeScript 3.8+) Applies thetype modifier to the entire import statement. All named imports within the destructured block are treated strictly as types.
type modifier to individual named imports. This allows mixing runtime value imports and type-only imports within a single AST node.
Compiler Mechanics and Type Erasure
- Forced Elision: Standard
importstatements in TypeScript are subject to implicit import elision; the compiler attempts to drop the import if it detects the imported bindings are only used in type positions. However,import typebypasses this heuristic, forcing the compiler to drop the import statement entirely during JavaScript emission regardless of context. - Value Position Restriction: Bindings imported via
import typecannot be evaluated at runtime. Attempting to use a type-imported binding in a value position (e.g., instantiating a class, passing it as an argument, or using it in a runtimetypeofcheck) will result in a compiler error (TS1361: 'X' cannot be used as a value because it was imported using 'import type'). - Class Behavior: When a class is imported using
import type, TypeScript extracts only its structural shape (instance properties and methods). The runtime constructor function is not imported. Consequently, the class can be used for type annotations but cannot be instantiated via thenewkeyword or subclassed via theextendsclause.
Compiler Configuration
The enforcement and behavior of type imports interact directly with specifictsconfig.json compiler options:
verbatimModuleSyntax: When enabled, TypeScript disables implicit import elision heuristics. Any standardimportis preserved in the emitted JavaScript exactly as written. To prevent a type-only module from being emitted and causing runtimeReferenceErrors, developers must use theimport typesyntax.isolatedModules: When using single-file transpilers (such as Babel, SWC, or esbuild), the transpiler cannot perform cross-file type analysis to determine if an ambiguous import is a type or a value.import typeprovides the explicit AST signal required by these external tools to safely strip the import without needing the full TypeScript type-checker context.
Master TypeScript with Deep Grasping Methodology!Learn More





