Gourav Pokharkar
Gourav Pokharkar

Reputation: 1648

TypeScript: Namespaces Vs Modules (Declarativeness)

I was looking for differences in Namespaces and Modules in TypeScript and come across one point that modules are declarative while namespaces are not. Also, modules can be imported in any order while namespaces can't. So, what does 'declarativeness' of modules means and how they work even when imported in random order?

Upvotes: 0

Views: 46

Answers (1)

Kokodoko
Kokodoko

Reputation: 28158

You can view namespaces as just wrapper objects around other objects, so the declaration order still matters.

Modules require extra code to make them even work.

This extra code is created in the window by your module bundler (webpack for example) and it holds references to all your modules. You can inspect it by opening the JS file generated by webpack.

The order of your modules is not important because they all get registered when you compile your bundle.

Upvotes: 1

Related Questions