Typescript parses each of our Typescript files into one of two modes:
- module mode: the file has any imports or exports
- script mode: the file does not use any imports or exports
We’ll almost always want to stick to Module mode.
Script mode
In script mode, any top-level variables we declare will be available to other files in the project without an explicit import, and we can safely consume global exports from third-party UMD modules without explicitly importing them first.
Use cases of script mode:
- To quickly prototype browser code that you plan to compile to no module system at all (
{"module": "none"}
) intsconfig.json
and include as raw<script />
tags in HTML file. - to create type declarations