/learn-typescript-module3

Show how typescript external modules are transpiled to javascript in different module format

Primary LanguageJavaScript

#Typescript Training

This sample project focuses on the Typescript external module writing. It shows how typescript module is transpiled to javascript (ES3). See the typescript handbook for more information.

In typescript the internal module must to be combine with the consumer, so I think it is less interesting than external module. The typescript transpiler knows how to wrap your module in 4 differents format (commonjs, amd, umd, system).

  • app folder contains typescript source files

    • Main.ts is the entry point it tests the modules M1 and M2
    • the module M1 requires the module M2
    • the module M2 requires the module M3
  • /gen* folders contains tranpiled javascript in different module formats: commonjs, amd, umd, system

  • You can execute the test with nodejs. Obviously only the commonjs and umd format are compatible with the nodejs module loader

    node genCommonjs/Main
    node genUmd/Main

##Quick link to the result

  • M2.ts orginal which requires M3 and export the class Cls2 and the object Inst2
  • M2 in commonjs format: no need to declare dependencies ahead.
  • M2 in umd: favorite format to publish opensource library which compatible with both amd and commonjs loaders (see also umdjs).
  • M2 in amd format: need to declare all dependencies ahead.

##See also