Book Image

TypeScript Essentials

By : Christopher Nance
Book Image

TypeScript Essentials

By: Christopher Nance

Overview of this book

Table of Contents (15 chapters)

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 variable as a parameter. Exported properties are then attached to this global variable. A module can contain any number of declarations of any type of object including other modules. Each of the declarations inside of a module can be either kept...