Install Typescript:
1
|
sudo npm install -g typescript
|
To check the Typescript version:
1
|
tsc --version
|
Typescript is just a superset of JavaScript. It is client side object oriented language. It follows classes, objects, Inheritance, Interface etc.. object oriented concepts like in Java or .net.
A valid JavaScript code is also valid typescript code. Because when you compile the typescript code it create a JavaScript file.
Example:
1
2
3
4
5
6
7
|
function log(message){
console.log(message);
}
var message = 'Coding 4 Developers';
log(message);
|
when you compile this main.ts file like:
1
|
tsc main.ts
|
a new file will generated here named as main.js.
if you are running an angular application it will be done automatically done by angular webpack we don't need to manually call ts complier.
When you run following commands:
1) ng serve
2) npm start
Typescript compiler called automatically and convert typescript code to JavaScript code.
if you check main.js it will have the JavaScript code like:
1
2
3
4
5
6
7
|
function log(message){
console.log(message);
}
var message = 'Coding 4 Developers';
log(message);
|
if you will run below command:
1
|
node main.js
|
it will print "Coding 4 Developers".