Make Mobile Apps with Ionic Framework 3 - Tutorial Part 3 #Installing Typescript & Write First Typescript Program

in #developer9 years ago (edited)

0.jpg

Hey SteemIt community. In this post I’m gonna show you How to Install TypeScript and write your first Typescript program.

How to Install Typescript

In previous posts I showed you how to install node.js and how to use npm for installing packages. Yeah, you’re right, we’re gonna install Typescript via npm.

npm install -g typescript

If you’re using a Mac or Linux based operating system, need permissin. So;

sudo npm install -g typescript

1.png

I’ve install the latest version of Typescript which is correctly version 2.4.2. I know elapsed time is 74 seconds. I hope Turkish Internet Service Providers will read this article. After the installation, test your installation. Inside your terminal, run tsc –version. Tsc = Typescript Compiler.
Conrats you installed Typescript to your computer.

Writing Hello SteemIt Program with Typescript

Now, I’m gonna create new folder named TypeScript-Example and new file named hello-steem.ts via my terminal.

  • Create new folder
    mkdir TypeScript-Exapmle

*Let’s go to this folder
cd TypeScript-Exapmle

*In here, I’m gonna create a new file and open it with Visual Studio Code
code hello-steem.ts

  • I’m gonna write some plan JavaScript code and I’m gonna show you that all this Jaavascipt code is so valid Typescript code.
// I’m defining a function named hello with message parameter
//And in this function, simply log that message in console

function hello(message) {
    console.log(message);
}

//I’m declaring a global variable named message

var message = ‘Hello, SteemIt!’

//Then I’m calling our function

hello(message);

This is totally plain Javascript code. We need to transpile this Typescript file into Javascript. Back to the fu.. No terminal.

tsc hello-steem.ts

If you look at this folder you will see another file named ‘hello-steem.js’.

Transpilation or compilation process was successfully completed. Conrats you wrote your first Typescript program. See you in next post.

By the way, I’m gonna execute our code with terminal.

node hello-steem.ts

Previous Chapter: What is Typescript

Next Chapter: Declaring Variable in Typescript

Coin Marketplace

STEEM 0.04
TRX 0.33
JST 0.081
BTC 59331.41
ETH 1557.21
USDT 1.00
SBD 0.42