About TypeScript namespace

TypeScript namespace

One of the most explicit namespace purpose is to solve the problem of the same name

Assume such a case, when a class has two students named Xiao Ming, in order to clearly distinguish them, we use the name outside, had to use some additional information, such as their surname (Wang Xiaoming, Li Xiaoming), or their parents' names, and so on.

Namespace defines the visible range identifiers, one identifier may be defined in multiple name spaces, it meanings in different namespace are unrelated. In this way, you can define a new namespace any identifiers that do not conflict with any existing identifier, because the existing definitions in other namespace.

TypeScript using namespace namespace is defined syntax is as follows:

namespace SomeNameSpaceName { 
   export interface ISomeInterfaceName {      }  
   export class SomeClassName {      }  
}

This defines a namespace SomeNameSpaceName,

If we need to call the class can SomeNameSpaceName classes and interfaces in the outside, you need to add classes and interfaces export keywords.

Namespace is common in the project, it is to distinguish the same name as the class

 

Guess you like

Origin www.cnblogs.com/mqflive81/p/11361151.html