Internal modules (module and namespace)

We can use the module and namespace keywords to define internal modules. TypeScript originally allowed us to use the module keyword to declare internal modules, but it was later deprecated in favor of the namespace keyword.

Internal modules (namespaces) can be used to encapsulate certain elements of an application and to provide our code with a better organization. However, we should try to avoid them and favor external modules over namespaces. External modules should be our preferred option because they are required by some tools that allow us to optimize certain aspects of our application. External modules will be covered in detail later in this chapter.

We can use namespaces to group interfaces, ...

Get Learning TypeScript 2.x - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.