While ES Modules (import / export) are the industry standard for modern TypeScript applications, namespaces (namespace Utility {}) allow scoping variables across legacy codebases.
TypeScript Modules and Namespaces
Organize code using ES modules (import/export) and internal namespaces.
Key Takeaways: TypeScript Modules and Namespaces
Mastering TypeScript Modules and Namespaces helps you write clean and reliable TypeScript code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
TypeScript Modules and Namespaces Code Example
TypeScriptnamespace MathHelper {
export const PI = 3.14159;
export function circleArea(r: number): number {
return PI * r * r;
}
}
console.log("Circle Area:", MathHelper.circleArea(10));
Output
Circle Area: 314.159
Free sign-in required · Google login available
Finished this lesson?
Mark it complete to track your progress.
Stuck on something?
Ask the community in the CodesInTech forum.
Need a developer?
Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.
Explore Our Services