TypeScript: Module System

A comprehensive guide to “Module System” in TypeScript (with examples)

In this lesson, we are going to take a look at how the ECMAScript module system works and how TypeScript implements module resolution strategies. In the end, we are going to learn how to create and publish a sample module written in TypeScript.

Uday Hiwarale
JsPoint
Published in
25 min readAug 2, 2020

--

(source: unsplash.com)

Before ES2015, JavaScript did not have a native module system. You had to use some third-party tools such as RequireJS or SystemJS to add support for modules. If you are using Webpack to bundle your project, then you do not need to worry about native module support at runtime. Webpack injects helpers to load module synchronously and asynchronously.

A module, in a nutshell, is a JavaScript file that operates in a sandbox environment and exposes some values to the public. It’s a normal JavaScript file with import statements to import modules and export statements to make a value (such as variable, function, class, etc.) available for import.

💡 To know more about modules and how they differentiate from normal script files, read the “Script vs Module” section of the Type System lesson.

--

--