Difference Between Internal & External Modules in TypeScript Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report In TypeScript, modules are a way to organize code and encapsulate functionality. There are two types of modules: internal modules (also known as namespaces) and external modules (also known as modules). Internal Modules (Namespaces):Internal modules, known as namespaces, provide a way to organize code within a single global scope. They help in avoiding naming conflicts by encapsulating code within a named container. Syntax:namespace MyNamespace { // code within the namespace}Example: Here, a namespace named MathOperations is created to group mathematical functions like addition and subtraction. The functions are then accessed within the namespace, showcasing the encapsulation provided by internal modules. JavaScript namespace MathOperations { export function add(x: number, y: number): number { return x + y; } export function subtract(x: number, y: number): number { return x - y; } } // Usage let resultAdd = MathOperations.add(5, 3); let resultSubtract = MathOperations.subtract(8, 2); console.log(resultAdd); // Output: 8 console.log(resultSubtract); // Output: 6 Output: 86External ModulesExternal modules allow you to organize code into separate files. Each file is treated as a separate module, and you can explicitly export and import functionalities between these modules. It is also known as the ES6 module. Syntax: File 1 (moduleA.ts): // moduleA.tsexport const variableA = 10;export function functionA(): void { // code}File 2 (moduleB.ts): // moduleB.tsimport { variableA, functionA } from './moduleA';// code using variableA and functionAExample: Here, moduleA.ts defines a namespace MathOperations, and moduleB.ts imports and uses the functionalities from moduleA. JavaScript // moduleA.ts export namespace MathOperations { export function add(x: number, y: number): number { return x + y; } export function subtract(x: number, y: number): number { return x - y; } } JavaScript // moduleB.ts import { MathOperations } from './moduleA'; // Usage let resultAdd = MathOperations.add(5, 3); let resultSubtract = MathOperations.subtract(8, 2); console.log(resultAdd); // Output: 8 console.log(resultSubtract); // Output: 6 Output: 86 Comment More infoAdvertise with us Next Article Difference Between Internal & External Modules in TypeScript A amanv09 Follow Improve Article Tags : JavaScript Web Technologies Similar Reads Difference between interfaces and classes in TypeScript In this article, we will see what is the Difference between "interface" and "Classes" in TypeScript. Interface: Interface is the virtual structure that is used for type-checking. In TypeScript we use interface keyword to create the new interface with identity. It create the structure for the same da 3 min read What's the Difference Between 'extends' and 'implements' in TypeScript ? TypeScript offers powerful way for organizing code and managing relationships between different components through the use of extends and implements keywords. This article explores the distinctions and functionalities of these two keywords.ExtendsThe extends keyword is used for two main purposes in 2 min read What is the difference between interface and type in TypeScript ? In TypeScript, both interface and type are used to define the structure of objects, but they differ in flexibility and usage. While interface is extendable and primarily for object shapes, type is more versatile, allowing unions, intersections, and more complex type definitions.Type in TypeScriptThe 3 min read What is the difference between 'String' and 'string' in TypeScript ? Unlike JavaScript, TypeScript uses static typing, i.e. it specifies what kind of data the variable will be able to hold. Since TypeScript is a superscript of JavaScript, it also holds a distinction between a string and String. The usage of a string object in JS (or TS for that matter) is very minima 4 min read Difference between Flow and TypeScript 1. Flow : Flow is developed and maintained by Facebook. It is a static type checker, designed to quickly find errors in JavaScript applications. Nothing more, nothing less. It's not a compiler, but a checker. It can work without any type of annotations and it is very good at inferring types. To enab 2 min read Difference between TypeScript and JavaScript Ever wondered about the difference between JavaScript and TypeScript? If you're into web development, knowing these two languages is super important. They might seem alike, but they're actually pretty different and can affect how you code and build stuff online.In this article, we'll break down the 4 min read What is the difference between Service Directive and Module in Angular ? Angular is a Typescript framework used to build dynamic and Single-Page Applications. This has a strong focus on modularity and reusability of code which helps in creating complex and maintainable applications. At the core, Angular has 3 fundamental building blocks, i.e., Service, Directive and Modu 6 min read Difference between npm install and npm update in Node.js NPM is like a powerhouse for Node.js that contains all the necessary modules for the smooth running of the node.js application. It gets installed on our machine when we install Node.js on our Windows, Linux or MAC OS. How to install Node on the machine? Refer to this article. NPM has 580096 register 5 min read What is the Difference Between a Module & a Namespace in JavaScript ? The dynamic web's programming language, JavaScript, has changed significantly over time. "Modules" and "Namespaces" are two particularly important architectural elements that have aided in the development of code organization. Modules in JavaScriptModules enable the control and organization of large 3 min read Differece between JavaScript Modules & NgModule Modules play an important role in structuring and organizing the code of Javascript and Angular.js. They help us to use the code efficiently. Majorly NgModule in Angular.js and Modules in Javascript are widely used in different scenarios. In this article, We will learn about Modules and their import 5 min read Like