-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

The TypeScript Workshop
By :

Consider the following TypeScript program – a simple function that adds two numbers:
Example 01.ts
1 function add (x, y) { 2 return x + y; 3 }
Link to the example on GitHub: https://packt.link/P9k6d
No, that's not a joke – that's real-life TypeScript. We just did not use any TypeScript-specific features. We can save this file as add.ts
and can compile it to JavaScript using the following command:
tsc add.ts
This will generate our output file, add.js
. If we open it and look inside, we can see that the generated JavaScript is as follows:
Example 01.js
1 function add(x, y) { 2 return x + y; 3 }
Link to the example on GitHub: https://packt.link/mTfWp
Yes, aside from some spacing, the code is identical, and we have our first successful transpilation.
We will add to the example, of course, but let's take a moment to analyze what happened. First of all...