Initially, TypeScript defined "internal modules" and "external modules":
- Internal modules: The
module
keyword was introduced in TypeScript to define internal modules. Internal modules were used to group
classes, interfaces, and functions into logical units.
- External modules refer to JavaScript modules, introduced in ECMAScript 2015. In TypeScript, just as in JavaScript (after ECMAScript 2015), any
file containing a top-level
import
or export
is considered a module.
However, in order to avoid confusion with similarly named terms, module
was deprecated in favor of the namespace
keyword,
and "external modules" became simply "modules", as to align with ECMAScript 2015’s terminology.
Now that namespace
is available, the use of module
is deprecated because it does the same thing, and its use could
confuse maintainers unaware of the history of the language. Therefore, the use of module
is discouraged in TypeScript code.
module myMod { // Noncompliant
// ...
}
Anywhere the module
keyword was used when declaring an internal module, the namespace
keyword should be used instead.
namespace myMod {
// ...
}