Bhushan Gadekar
Bhushan Gadekar

Reputation: 13805

How typescript is converted to javascript in angular2?

I am learning angular2 with typescript.Its quite fascinating to work but I am facing trouble understanding the actual working of any application as the code we have written will be in typescript.but the code to be executed is always in ECMAScript.

I have heard about transpiler but couldnt understand more about it.

I was just wondering how this functionality has been achieved?

Upvotes: 4

Views: 6028

Answers (1)

Thierry Templier
Thierry Templier

Reputation: 202296

There are two ways to do that:

  • Transpiling on the fly (like how it's done in plunkr):

    <script>
      System.config({
        transpiler: 'typescript', 
        typescriptOptions: { emitDecoratorMetadata: true }, 
        packages: {
          'app': {
            defaultExtension: 'ts'
          }
        } 
      });
      (...)
    </script>
    

    Here is a sample: https://plnkr.co/edit/aG4TdHbAls3cu04AAt64

  • Preprocess TypeScript files using the typeScript compiler. Then you only rely on compiled JavaScript files. Such approach is described in the 5min quickstart on angular.io: https://angular.io/guide/quickstart.

Upvotes: 3

Related Questions