If you now create a new file bar.ts
in the same project, you will be allowed by the TypeScript type system to use the variable foo
as if it was available globally:
File Module
Also called external modules. If you have an import
or an export
at the root level of a TypeScript file then it creates a local scope within that file. So if we were to change the previous to the following (note the export
usage):
If you want to use stuff from foo.ts
in you need to explicitly import it. This is shown in an updated bar.ts
below:
What JavaScript is generated from a given TypeScript file that uses external modules is driven by the compiler flag called module
.