Mrs. Sujata Oak Assistant Professor Department of It: Itc602-Web X.O Module 2: Typescript
Mrs. Sujata Oak Assistant Professor Department of It: Itc602-Web X.O Module 2: Typescript
Mrs. Sujata Oak Assistant Professor Department of It: Itc602-Web X.O Module 2: Typescript
O
Module 2 : TypeScript
https://www.tutorialsteacher.com/typescript/t
ypescript-overview
Overview
TypeScript Internal Architecture
TypeScript Environment Setup
Module 2 : Type Script
1. TypeScript supports Static typing, Strongly type, Modules, Optional Parameters, etc.
the code, and if any error found, then it highlighted the mistakes before the script is
run.
https://www.javatpoint.com/install-nodejs
https://nodejs.org/en/
To verify the installation was successful, enter the following command in the Terminal
Window.
$ node -v
$ npm -v
npm install -g typescript
$ tsc -v
https://code.visualstudio.com/download
HELLO WORLD
2.They cannot contain spaces and special characters, except the underscore (_)
1. If Statement
2. If else statement
3. if else if statement
If Statement:
If statement is used to execute a block of statements if specified condition
is true.
if(condition){
//Block of
TypeScript
statements. }
switch(expression) {
case constant-expression1: {
//statements;
break;
}
case constant_expression2: {
//statements;
break;
}
default: {
//statements;
break;
}
}
1. Named Function
2. Anonymous Function
3. Arrow Function
4. Function Overloading
return a + b;
Function overloading with different number of parameters and types with same name is not
supported.
DEMO
1.It saves the memory space so that program execution becomes fast.
A Class Contains
Constructor
Properties
Methods
What Is an Object?
DEMO
40 Module 2 : Type Script
Fundamentals of Type Script : Classes and Objects DEMO
class Employee {
eid:number; Created New Class and Object
ename:string; Initialize Variables using object variables
deptno:number;
display():void
{
console.log(this.eid);
console.log(this.ename);
console.log(this.deptno);
}
}
setData(eid:number,ename:string,deptno:number):void
{
this.eid=id;
this.ename=ename;
this.deptno=deptno;
}
display():void
{
console.log(this.eid);
console.log(this.ename);
console.log(this.deptno);
}
}
var emp1=new Employee();
emp1.setData(110,"Shruti",10);
42 Module 2 : Type Script
Fundamentals of Type Script : Classes and Objects DEMO
Initialize Variables using Constructor
The constructor is a special type of method which is called when
creating an object. In TypeScript, the constructor method is always
defined with the name "constructor".
constructor(eid:number,ename:string,deptno:number)
{
this.eid=eid;
this.ename=ename;
this.deptno=deptno;
}
BUT,
DEMO
DEMO
48 Module 2 : Type Script
Fundamentals of Type Script : Interfaces
Interfaces define properties, methods, and events, which are the members of
the interface. Interfaces contain only the declaration of the members.
public
By default, all members of a class in TypeScript are public. All the
public members can be accessed anywhere without any restrictions.
private
The private access modifier ensures that class members are visible
only to that class and are not accessible outside the containing class.