Modules

The module pattern has become increasingly popular in JavaScript development. It provides an easy way to encapsulate private members, something that isn't inherently available in JavaScript, and keep objects off the global namespace. In TypeScript there are two types of modules: internal modules and external modules. We will discuss them both in detail, but for now let's just talk about internal modules.

Internal modules

Internal modules represent a namespace that classes, interfaces, enums, variables, code segments, and other namespaces can exist inside of. They are created inside of a closure just like classes are. However, modules don't return a function that gets assigned to a global variable. Modules execute the closure with a global ...

Get TypeScript Essentials 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.