Namespaces

Namespaces are another way to isolate elements in your TypeScript applications. Using the namespace keyword, you can define an isolated namespace to avoid name clashes.

In practice, we don't recommend using namespaces, which is why we won't cover them in any more detail here. Modules provide everything you need to properly isolate code. Modules are more interesting since they declare their dependencies, which allows bundlers to remove unused code.

At the end of the day, modules win in terms of isolation, code reuse, and tooling support. This is true for both web and server-side applications. Also, remember that modules are supported natively from ES2015 onward.

One case where namespaces are very useful is when you are creating type definitions for JavaScript libraries.

There is one more point that we need to address before we start developing our new application together: How does TypeScript resolve imports?