Difference between a module and a script
In TypeScript, any file containing a top-level import or export is treated as a module. Modules execute in their own scope, meaning variables, functions, classes, etc., declared in a module are not visible outside unless explicitly exported. Files without top-level imports or exports are considered scripts and share the global scope.
If a TypeScript file does not have any import
or export
statements, but you would like it to be considered a module, add an empty export object.