to install Type script
npm install -g typescript
to check the version
tsc -v
What is typescript
a. Created by Microsoft in 2011
b. It is a superset of Javascript
c. It helps to generate most optimized javascript code
d. It is typesafe (where we have datatypes)
e. No compile time error in javascript , but do exists in typescript
f. Transpilation is the process for converting ts to js
g. Easy to upgrade the js version, if we have written our code using Typescript
The files are saved with extension of "*.ts"
To compile the typescript to javascript
tsc <<typescript filename>>
We have datatypes in Typescript
String or string
boolean or Boolean
Date
uniontypes --> So the variable can hold multiple datatypes
let empid: String | number;
empid = 10;
empid = "emp10";
any --> The variable can store any datatye value like strinh, number,date,array,json etc.
Generic --> To have a same datatype to be stored in an array
javascript version is called ECMAScript5 and EcmaScript6.
Variable in typescript need to be declared using the keyword let
let name:string = "Pavan"
Loop
forEach --> to loop an array we use this
Eg:
for -of --> to loop an array we use this
Eg:
For-in --> to loop an array and we will get the index position
Eg:
Arrow function or Lamda expression (=>)
To have the function in one line we will use it
IIFE --> Immediate invoke function Expression
Anonymous function
Class is defined like other OOP languages
constructor()
npm install -g typescript
to check the version
tsc -v
What is typescript
a. Created by Microsoft in 2011
b. It is a superset of Javascript
c. It helps to generate most optimized javascript code
d. It is typesafe (where we have datatypes)
e. No compile time error in javascript , but do exists in typescript
f. Transpilation is the process for converting ts to js
g. Easy to upgrade the js version, if we have written our code using Typescript
The files are saved with extension of "*.ts"
To compile the typescript to javascript
tsc <<typescript filename>>
We have datatypes in Typescript
String or string
boolean or Boolean
Date
uniontypes --> So the variable can hold multiple datatypes
let empid: String | number;
empid = 10;
empid = "emp10";
any --> The variable can store any datatye value like strinh, number,date,array,json etc.
Generic --> To have a same datatype to be stored in an array
javascript version is called ECMAScript5 and EcmaScript6.
Variable in typescript need to be declared using the keyword let
let name:string = "Pavan"
Loop
forEach --> to loop an array we use this
Eg:
let departments : Array<string> = new Array<string>();
departments.push('IT');
departments.push('Marketing');
departments.forEach(function(dept){
console.log(dept);
});
for -of --> to loop an array we use this
Eg:
let department : Array<any> = new Array<any>();
department.push('IT');
department.push(10);
for(let dept of department){
console.log(dept);
}
For-in --> to loop an array and we will get the index position
Eg:
let departments : Array<string> = new Array<string>();
departments.push('IT');
departments.push('Marketing');
for(let dept in departments){
console.log(dept);
}
Arrow function or Lamda expression (=>)
To have the function in one line we will use it
let students : Array<string> = new Array<string>();
students.push('Pavan');
students.push('Kumar');
students.forEach((student) => console.log(student));
IIFE --> Immediate invoke function Expression
Anonymous function
Class is defined like other OOP languages
constructor()