What's the difference between internal and external modules in TypeScript?

后端 未结 4 964
萌比男神i
萌比男神i 2020-12-14 00:05

I have spent some time reading the Typescript language specification and am somewhat confused about the difference between internal and external

4条回答
  •  醉酒成梦
    2020-12-14 00:44

    According to Anders presentations: http://channel9.msdn.com/posts/Anders-Hejlsberg-Introducing-TypeScript (34:40) and Typescript documentation, the external modules are modules which are based on top AMD (Asynchronous Model Definition) or CommonJS.

    External modules are useful in sense they hide the internal statements of the module definitions and show only the methods and parameters associated to the declared variable.

    Suppose you have a Main class with a defined log method placed in a transfer.js file. The internal methods of the Main class are only visible when you are importing the transfer.js file at the top of the source js file as so: ///. This way the compiler eliminates the traversal of all js files at runtime.

    This is a huge benefit of using external modules. Another one is when you are trying to reference an external method or class which in the normal top-down javascript flow is defined later than the method invocation. Using external modules the referenced class is instantiated only on method invocation.

提交回复
热议问题