Visit complete TypeScript roadmap
TypeScript Topic

Modules

Modules

In TypeScript, modules are used to organize and reuse code. There are two types of modules in TypeScript:

  • Internal
  • External

Internal modules are used to organize code within a file and are also referred to as namespaces. They are defined using the “namespace” keyword.

External modules are used to organize code across multiple files. They are defined using the “export” keyword in one file and the “import” keyword in another file. External modules in TypeScript follow the CommonJS or ES modules standards.

Here is an example of how you can use internal modules in TypeScript:

// myModule.ts
namespace MyModule {
  export function doSomething() {
    console.log('Doing something...');
  }
}

// main.ts
/// <reference path="myModule.ts" />
MyModule.doSomething(); // Output: "Doing something..."

Learn more from the following links:

More Topics

Explore related content

View All Topics
Loved by 100K+ Developers

Start Your Learning
Journey Today

Join thousands of developers who are leveling up their skills with structured roadmaps and expert guidance

No credit card required
Always free
Track your progress