Info
Open the page on your phone

Tell about namespaces and modules in TypeScript

In TypeScript, namespaces are used to organize related code, with the purpose of avoiding naming conflicts. This can be helpful when working with large codebases or incorporating third-party libraries. On the other hand, modules are more versatile and widely used for organizing code into reusable components. They help in creating a clear separation of concerns and can be used to structure code within an application.

Namespaces and modules in TypeScript are distinct but complementary tools for managing and structuring code. Understanding the differences and applications of both namespaces and modules is essential for any TypeScript developer, as it enables them to efficiently organize and encapsulate their code, leading to more maintainable and scalable applications.

                        
namespace MyNamespace {
    export interface MyInterface {
        // оголошення інтерфейсу
    }
    export function myFunction() {
        // реалізація функції
    }
}

// Імпорт модулю
import { MyNamespace } from './path/to/MyNamespace';