Mechanics and Behavior
Scope and Binding Unlike standard import declarations, a side-effect import does not introduce any local variables, functions, or types into the importing module’s namespace. The target module is evaluated, but itsexport statements are ignored by the importing file.
Compiler Emit and Elision
The TypeScript compiler (tsc) performs import elision: it removes import statements from the emitted JavaScript if it determines the imported members are only used in type positions. However, side-effect imports are strictly exempt from this process. The compiler guarantees that a side-effect import is never elided and will always be preserved in the compiled JavaScript output.
Type System Integration
During the compilation phase, TypeScript parses the target module of a side-effect import. If the target module contains ambient declarations or global type augmentations, the compiler applies them to the global type environment.
import statement. Per the specification, the module is evaluated exactly once, regardless of how many times it is imported across the application.
Tired of Poor TypeScript Skills? Fix That With Deep Grasping!Learn More





