Open In App

What is the purpose of using namespace in TypeScript ?

Last Updated : 23 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The namespaces in TypeScript are used to organize and encapsulate the related functionalities and methods into a particular name code block to reuse them again and again in the code whenever we need the same functionality. There are some key purposes for using namespace in TypeScript as written below:

  • Logical collection: It helps in grouping the logically same functionalities into a single code block and organizes logical code.
  • Avoiding named collisions: It provides a separate scope and a unique namespace for the identifies which may help in avoiding the name collisions in the code.
  • Encapsulation: The code written inside a namespace will be encapsulated just like the classes in TypeScript.
  • Code Reusability: The code written inside a namespace can be used anywhere in the whole code just by accessing the values and properties stored inside it.

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads