Modules

TypeScript modules are quite similar to ES6 modules, so you should be familiar with their construct already. Modules enable encapsulation and reuse, and allow dependency order resolution.

The scope of TypeScript modules are bound to files. Every file is a module and its internal declarations should not conflict with anything external. When a module desires to expose a declaration, such as a function, class, and even a constant, you can use the export keyword. On the other hand, if a module needs an exported member from another module, the import keyword is used.

Moreover, the TypeScript compiler supports generating TypeScript modules out to several formats, for example, CommonJS, ES6, and more. This means that you can use TypeScript ...

Get Hands-On Full-Stack Web Development with ASP.NET Core 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.