Typically, Typescript modules are declared like
declare module MyModule {
....
}
but sometimes I also see it like
declare
As outlined in the Typescript docs, there is a difference between the two styles. module x {
is equivalent to namespace x {
, while module "x" {
is unlike either of the other two. This is definitely confusing, which is why the documentation using the latter syntax in all cases.
The question then must be asked, what is the difference between a namepsace and a so-called external module (i.e., a module that is declared with quotes)?
We get some insight from the docs:
Just like namespaces, modules can contain both code and declarations. The main difference is that modules declare their dependencies.
Modules also have a dependency on a module loader (such as CommonJs/Require.js).
Essentially, using the quotes indicates that it is indeed a module in the traditional Javascript sense that requires explicit import to be used. Without the quotes, you just create a global object that can be referenced and utilized without any explicit require
s.