Mastering basics is the key to become successful in any technology. We’ve already seen What is TypeScript, What are the advantages and features of it, in our previous article. In this article we will be seeing how to get started with TypeScript, how to create program using the same. So let’s get started!!
In this post we will understand how TypeScript file compiles and run, We will be creating sample program for the same.
Step 1: Open any Editor, In my case I will be using Visual Studio Code, you can download the same from here if you don’t have.
Step 2: Open the Editor, Create new file and name it Sample.ts.
Step 3: Now in the same file we will be writing basic code, we will be starting with “Hello Nuclear Geeks” program.
Step 4: Write the below code in your Sample.ts file and save it.
var message: string = "Hello Nuclear Geeks " console.log(message)
We’re done with our sample program, Before we run the same let’s try to understand what we did, We’ve defined a variable name message of type string and assigned the message “Hello Nuclear Geeks”. Later we are printing the same message.
Once you’re done with the Node.js download check the installation by typing
$ node --version v10.16.0$
Step 6: So now we’re done with the setup, Let’s run the program, Open the terminal and type
$ tsc Sample.ts
$ node Sample.js Hello Nuclear Geeks
And, here you see your output!
So, In this post we’ve seen how one can get started with TypeScript and start building sample programs and application. Do let me know in the comment section if you’ve any queries.
One thought on “GETTING STARTED WITH TYPESCRIPT”