Microsoft Introduced TypeScript in 2012. As per the official website of TypeScript,
TypeScript makes it easier to organize our code and it supports Object Oriented programming, like C#, Java, etc. We can use class, namespace, inheritance, etc., so it is very helpful when we are going for very large application and we are handling most of the things in UI side.
TypeScript will check all types of errors at the time of compilation only, so we don’t need to wait for runtime check.
TypeScript also supports other JS libraries.
The most popular framework, Angular, also uses TypeScript.
As per the TypeScript official website, Brad Green, Engineering Director of AngularJS said the below comment about TypeScript.
“We love TypeScript for many things… With TypeScript, several of our team members have said things like ‘I now actually understand most of our own code!’ because they can easily traverse it and understand relationships much better. And we’ve found several bugs via TypeScript’s checks.”
— Brad Green, Engineering Director – AngularJS
Below are some more comments from others.
“One of Ionic’s main goals is to make app development as quick and easy as possible, and the tooling support TypeScript gives us with autocompletion, type checking and source documentation really aligns with that.”
— Tim Lancina, Tooling Developer – Ionic
— Valio Stoychev, PM Lead – NativeScript
“TypeScript has helped ensure that Dojo 2 will be built on rock solid foundations, which will make enterprise development better. TypeScript gives us all the benefits of ES6, plus more productivity, … and responsive support from the TypeScript team.”
— Dylan Schiemann, Co-founder – Dojo Toolkit, CEO – SitePen
— Aaron Cornelius, Research Fellow – Epic
After knowing this many facts about TypeScript, how you are feeling, it’s good, isn’t it?
Now, it is time to write code in TypeScript, but before that, we have to install TS in our system. If we are using Visual Studio 2015 Update 3 or Visual Studio 2017, then we don’t have to worry about the installation of TypeScript. It includes TypeScript by default but this is not necessary to use Visual Studio or any other particular IDE for using TypeScript. We can use any editor or even notepad also to use TypeScript.
If we are using a different platform or we don’t want to use Visual Studio, then we have to use any text editor and the TypeScript npm package to use TypeScript. We can go for Node.js, WebStorm, Atom, SubLime Text, Eclipse, etc. as a tect editor.
Here, we are going through the Node.js and notepad to see how to use TypeScript.
First of all, we have to download Node.js and install it in our system. Please click here to install the Node.js and we can download the Node.js source code or a pre-built installer as per our platform.
Here, we are going to download Windows Installer (.msi) as per my OS. After installing the file, run the installer as described below.
Double click on the file (node-v6.11.0-x64.msi).
After reading the License Agreement, check the checkbox of “I accept the terms in the License Agreement” and click Next.
We will get the folder location where we want to install it. We are leaving it intact. Click Next
Click “Install” button to install Node.js.
Yes, we are done with the installation of Node.js. Now, let’s install TypeScript.
First of all, open Node.js command prompt from the Start menu.
Type the below command in command prompt.
npm install -g typescript
We have installed TypeScript successfully.
Now, right click on the screen and click New -> Text Document and create the txt file. Give it a desired name and change the extension as .ts, as shown in the below image.
Open and edit this file in Notepad. We are going to write the below code in our first.ts TypeScript file.
alert(“My First TypeScript Program”);
Now, save the file.
Compilation of TypeScript
Open the Node.js command prompt from the Start menu and go to the file location using command line and write the following command.
In this article, we have covered the introduction of TypeScript, why we need TypeScript, its installation, and its compilation process with Node.js.