In this short example, I will show you the easiest path to create your first typescript program using Visual Studio Code IDE in windows OS. Visual Studio Code is a free-to-use IDE that can help us write various programs using the most popular programming languages such as C++, C#, and Javascript! When you want to run a typescript program in Visual Studio Code you will need to compile the program into Javascript first and then use Node.js to run that Javascript program later.
Alright, let us first start to create an empty typescript file in a subfolder under the Visual Studio Code main folder. Open up the Windows PowerShell console and make a new subdirectory under the current Visual Studio Code directory like this…
mkdir typescript
Next, create an empty typescript file as follows:
New-Item example1.ts
Now launch the Visual Studio Code IDE within this same subdirectory as follows:
code .
The dot sign above means the current subdirectory…
Alright, now let us write a few lines of typescript code and then compile the program. Click on the example1.ts file on the left pane of the ide to open up the empty file on the right pane and start to enter the below code into it!
function oneplusone(number1 : number, number2 : number) { console.log(number1+number2); } oneplusone(1,5); // will generate 6
After this typed in tsc example1.ts in the PowerShell to generate the Javascript file from this typescript program.
Now you can debug the Javascript file by clicking on the file on the left pane of the Studio and then selecting the Run menu and the Start Debugging sub-menu to debug and run it. When the pop-up appears on the screen just select Node.js to debug the program!
This is basically it! But why you might ask yourself that you must get into such trouble just to create the typescript file and then turns it to Javascript later on instead of directly write the program using Javascript? Well, there certainly has lots of benefits to typescript which you will learn once you have completely mastered this new programming language so I don’t even bother to explain to you in detail in this simple article! Have fun type scripting 🙂