JavaScript, as the language has gotten more complex, has realized that it needs to have the ability to easily import and export code from other modules, while not degrading the performance of a webpage. This is because, by default, a webpage downloads a script and processes it once downloaded, all while blocking all other downloads and screen rendering, in case changes are made to the DOM in that script.
Therefore, JavaScript is known as a blocking tag, and many who work on improving webpage performance try to avoid JavaScript, or push all the JavaScript code to the bottom of the page. Luckily, JavaScript has been working on ways to overcome that issue.
In TypeScript, just as in ECMAScript 2015, any file containing a top-level import
or export
is considered a module.
In the JavaScript specification, any JavaScript files without an import
declaration, export
, or top-level await
should be considered a script and not a module. This means it is run, once it downloads. If you have a file that doesn’t currently have any import
s or export
s, but you want to be treated as a module, add the line:
export {};
You can read more about modules and importing and exporting them on the TypeScript page: https://www.typescriptlang.org/docs/handbook/2/modules.html
Importing and Exporting Modules was originally found on Access 2 Learn