SlideShare ist ein Scribd-Unternehmen logo
1 von 30
14 December 2017 www.snipe.co.in 1
SNIPE TEAM
12/14/2017
TYPESCRIPT
12/14/2017
3
CONTENTS
TypeScript is a typed superset of JavaScript that compiles to plain
JavaScript.
 TypeScript is pure object oriented with classes, interfaces and statically
typed like C# or Java.
 The popular JavaScript framework Angular 2.0 is written in TypeScript.
 Mastering TypeScript can help programmers to write object-oriented
programs and have them compiled to JavaScript, both on server side and
client side.
12/14/2017 4
INTRODUCTION
 Anders Hejlsberg, lead architect of C# and
worked on the development of TypeScript.
 TypeScript was first made public in October 2012
(at version 0.8), after two years of internal
development at Microsoft.
 On 22 September 2016, TypeScript 2.0 was
released.
12/14/2017 5
HISTORY
TYPESCRIPT
What is TypeScript?
• TypeScript is a strongly typed, object oriented, compiled language.
• TypeScript is both a language and a set of tools.
• TypeScript is a typed superset of JavaScript compiled to JavaScript.
• In other words, TypeScript is JavaScript plus some additional features.
12/14/2017 6
JAVASCRIPT
The benefits of TypeScript include −
 Compilation − JavaScript is an interpreted language. TypeScript will
compile the code and generate compilation errors, if it finds some sort
of syntax errors. This helps to highlight errors before the script is run.
 Strong Static Typing − JavaScript is not strongly typed. TypeScript
comes with an optional static typing and type inference system through
the TLS (TypeScript Language Service). The type of a variable, declared
with no type, may be inferred by the TLS based on its value.
 TypeScript supports Object Oriented Programming concepts like
classes, interfaces, inheritance, etc.
12/14/2017 7
WHY USE TYPESCRIPT?
Features of TypeScript
• TypeScript is just JavaScript. TypeScript starts with JavaScript and
ends with JavaScript. Typescript adopts the basic building blocks of
your program from JavaScript. Hence, you only need to know JavaScript
to use TypeScript. All TypeScript code is converted into its JavaScript
equivalent for the purpose of execution.
• TypeScript supports other JS libraries. Compiled TypeScript can be
consumed from any JavaScript code. TypeScript-generated JavaScript
can reuse all of the existing JavaScript frameworks, tools, and libraries.
• JavaScript is TypeScript. This means that any valid .js file can be
renamed to .ts and compiled with other TypeScript files.
• TypeScript is portable. TypeScript is portable across browsers, devices,
and operating systems. It can run on any environment that JavaScript
runs on. Unlike its counterparts, TypeScript doesn’t need a dedicated VM
or a specific runtime environment to execute.
12/14/2017 8
FEATURES
 The ECMAScript specification is a standardized specification of a
scripting language. There are six editions of ECMA-262 published.
Version 6 of the standard is codenamed "Harmony". TypeScript is aligned
with the ECMAScript6 specification.
 TypeScript adopts its basic language features from the ECMAScript5
specification, i.e., the official specification for JavaScript. TypeScript
language features like Modules and class-based orientation are in line
with the EcmaScript 6 specification. Additionally, TypeScript also
embraces features like generics and type annotations that aren’t a part
of the EcmaScript6 specification.
12/14/2017 9
TYPESCRIPT AND ECMASCRIPT
ADDITIONAL
FEATURES
ECMASCRIPT5
ECMASCRIPT5 TYPESCRIPT
TypeScript has the following three components:
 Language − It comprises of the syntax, keywords, and type annotations.
 Compiler − The TypeScript compiler (tsc) converts the instructions written in
TypeScript to its JavaScript equivalent.
 Language Service − The "Language Service" exposes an additional layer around
the core compiler pipeline that are editor-like applications. The language
service supports the common set of a typical editor operations like statement
completions, signature help, code formatting and outlining, colorization, etc.
12/14/2017 10
COMPONENTS OF TYPESCRIPT
12/14/2017 11
COMPONENTS OF TYPESCRIPT
Language
service
compiler
Declaration Files
 When a TypeScript script gets compiled, there is an option to generate
a declaration file (with the extension .d.ts) that functions as an
interface to the components in the compiled JavaScript.
 The concept of declaration files is analogous to the concept of header
files found in C/C++. The declaration files (files with .d.ts extension)
provide intellisense for types, function calls, and variable support for
JavaScript libraries like jQuery, MooTools, etc.
12/14/2017 12
DECLARATION FILES
Local Environment Setup
Typescript is an Open Source technology. It can run on any browser, any
host, and any OS. You will need the following tools to write and test a
Typescript program −
 A Text Editor
 The text editor helps you to write your source code. Examples of a few
editors include Windows Notepad, Notepad++, Emacs, vim or vi, etc.
Editors used may vary with Operating Systems.
 The source files are typically named with the extension .ts
12/14/2017 13
ENVIRONMENT SETUP
The TypeScript compiler is itself a .ts file compiled down to JavaScript
(.js) file. The TSC (TypeScript Compiler) is a source-to-source compiler
(transcompiler / transpiler).
 The TSC generates a JavaScript version of the .ts file passed to it. In
other words, the TSC produces an equivalent JavaScript source code
from the Typescript file given as an input to it. This process is termed as
transpilation.
 However, the compiler rejects any raw JavaScript file passed to it. The
compiler deals with only .ts or .d.ts files.
12/14/2017 14
ENVIRONMENT SETUP
app.jstsc app.tsapp.ts
 Installing Node.js
 Node.js is an open source, cross-platform runtime environment for
server-side JavaScript. Node.js is required to run JavaScript without a
browser support. It uses Google V8 JavaScript engine to execute code.
You may download Node.js source code or a pre-built installer for your
platform.
 Step 1 − Download and run the .msi installer for Node
 Step 2 − To verify if the installation was successful, enter the
command node –v in the terminal window.
 Step 3 − Type the following command in the terminal window to install
TypeScript.
 npm install -g typescript
12/14/2017 15
ENVIRONMENT SETUP
var message:string = "Hello World"
console.log(message)
12/14/2017 16
 Your First TypeScript Code
 Let us start with the traditional “Hello World” example −
BASIC SYNTAX
//Generated by typescript 1.8.10 var message =
"Hello World"; console.log(message);
12/14/2017 17
BASIC SYNTAX
On compiling, it will generate following JavaScript code.
//Generated by typescript 1.8.10 var message = "Hello World";
console.log(message);Line 1 declares a variable by the name message.
Variables are a mechanism to store values in a program.
Line 2 prints the variable’s value to the prompt. Here, console refers to
the terminal window. The function log () is used to display text on the
screen.
Let us see how to compile and execute a TypeScript program using Visual
Studio Code. Follow the steps given below −
 Step 1 − Save the file with .ts extension. We shall save the file as
Test.ts. The code editor marks errors in the code, if any, while you save
it.
 Step 2 − Right-click the TypeScript file under the Working Files option
in VS Code’s Explore Pane. Select Open in Command Prompt option.
 Step 3 − To compile the file use the following command on the terminal
window.

 Step 4 − The file is compiled to Test.js. To run the program written,
type the following in the terminal.
12/14/2017 18
COMPILE AND EXECUTE A TYPESCRIPT PROGRAM
tsc Test.ts
node Test.js
Test.ts
class Greeting {
greet():void {
console.log("Hello World!!!")
}
}
var obj = new Greeting();
obj.greet();
12/14/2017 19
EXAMPLE
Test.js
var Greeting = /** @class */
(function () {
function Greeting() {
}
Greeting.prototype.greet =
function () {
console.log("Hello World!!!");
};
return Greeting;
}());
var obj = new Greeting();
obj.greet();
TypeScript is object oriented JavaScript. TypeScript supports
object-oriented programming features like classes, interfaces, etc. A
class in terms of OOP is a blueprint for creating objects. A class
encapsulates data for the object. Typescript gives built in support for
this concept called class.
Creating classes
Use the class keyword to declare a class in TypeScript. The syntax for
the same is given below −
• Syntax:
12/14/2017 20
CLASSES
class class_name {
//class scope
}
Example: Declaring a
class
class Car {
//field engine:string;
//constructor
constructor(engine:string
) {
this.engine = engine
} //function
disp():void {
console.log("Engine is :
"+this.engine)
}
}
12/14/2017 21
CLASSES
//Generated by typescript 1.8.10
var Car = (function () {
//constructor
function Car(engine) { this.engine =
engine;
}
//function Car.prototype.disp =
function () { console.log("Engine is :
" + this.engine); };
return Car;
}());
A module is designed with the idea to organize code written in
TypeScript. Modules are broadly divided into −
 Internal Modules
 External Modules
Internal Module:
Internal modules came in earlier version of Typescript. This was used
to logically group classes, interfaces, functions into one unit and can be
exported in another module. This logical grouping is named namespace in
latest version of TypeScript.
12/14/2017 22
MODULES
Internal Module Syntax:
12/14/2017 23
MODULES
namespace snipe community{
export function add(x, y) { console.log(x + y);}
}
var snipe community;
(function (snipe community){
function add(x, y)
{ console.log(x + y);
} snipe community.add = add;
})(snipe community || (snipe community = {}));
JavaScript generated in both cases are same:
External Module:
External modules in TypeScript exists to specify and load
dependencies between multiple external js files. If there is only one js file
used, then external modules are not relevant. Traditionally dependency
management between JavaScript files was done using browser script tags
(<script></script>).
Syntax-
12/14/2017 24
MODULES
//FileName : SomeInterface.ts
export interface SomeInterface {
//code declarations
}
External Module:
Example
/ IShape.ts
export interface IShape {
draw();
} // Circle.ts
import shape = require("./IShape");
export class Circle implements shape.IShape {
public draw()
{ console.log("Cirlce is drawn (external module)");
}
} // Triangle.ts
import shape = require("./IShape");
export class Triangle implements shape.IShape {
public draw() { console.log("Triangle is drawn (external module)"); }
}
// TestShape.ts
Import shape = require("./IShape");
import circle = require("./Circle");
import triangle = require("./Triangle");
function drawAllShapes(shapeToDraw: shape.IShape) {
shapeToDraw.draw();
}
drawAllShapes(new circle.Circle());
drawAllShapes(new triangle.Triangle());
12/14/2017 25
MODULES
The command to compile the main TypeScript file for AMD systems is −
On compiling, it will generate following JavaScript code for AMD.
File:IShape.js
12/14/2017 26
MODULES
tsc --module amd TestShape.ts
//Generated by typescript 1.8.10
define(["require", "exports"], function (require, exports) {
});
File:Circle.js
12/14/2017 27
MODULES
define(["require", "exports"], function (require, exports) {
var Circle = (function () {
function Circle() {
} Circle.prototype.draw = function () {
console.log("Cirlce is drawn (external module)");
};
return Circle;
})();
exports.Circle = Circle;
});
File:Triangle.js
12/14/2017 28
MODULES
define(["require", "exports"], function (require, exports) {
var Triangle = (function () {
function Triangle() {
}
Triangle.prototype.draw=function () {
console.log("Triangle is drawn (external module)");
};
return Triangle;
})();
exports.Triangle = Triangle;
});
TypeScript lets you write JavaScript the way you really want to.
TypeScript is a typed superset of JavaScript that compiles to plain
JavaScript. TypeScript is pure object oriented with classes, interfaces and
statically typed like C# or Java. The popular JavaScript
framework Angular 2.0 is written in TypeScript. Mastering TypeScript can
help programmers to write object-oriented programs and have them
compiled to JavaScript, both on server side and client side.
12/14/2017 29
CONCLUSION
THANK YOU
12/14/2017 30

Weitere ähnliche Inhalte

Was ist angesagt?

Project Presentation on Advance Java
Project Presentation on Advance JavaProject Presentation on Advance Java
Project Presentation on Advance Java
Vikas Goyal
 
Node.js an introduction
Node.js   an introductionNode.js   an introduction
Node.js an introduction
Meraj Khattak
 
108 advancedjava
108 advancedjava108 advancedjava
108 advancedjava
Anil Kumar
 

Was ist angesagt? (20)

Next.js with drupal, the good parts
Next.js with drupal, the good partsNext.js with drupal, the good parts
Next.js with drupal, the good parts
 
Project Presentation on Advance Java
Project Presentation on Advance JavaProject Presentation on Advance Java
Project Presentation on Advance Java
 
Web services engine
Web services engineWeb services engine
Web services engine
 
Node.js an introduction
Node.js   an introductionNode.js   an introduction
Node.js an introduction
 
Spring Boot on Amazon Web Services with Spring Cloud AWS
Spring Boot on Amazon Web Services with Spring Cloud AWSSpring Boot on Amazon Web Services with Spring Cloud AWS
Spring Boot on Amazon Web Services with Spring Cloud AWS
 
OpenNTF Domino API (ODA): Super-Charging Domino Development
OpenNTF Domino API (ODA): Super-Charging Domino DevelopmentOpenNTF Domino API (ODA): Super-Charging Domino Development
OpenNTF Domino API (ODA): Super-Charging Domino Development
 
From User Action to Framework Reaction
From User Action to Framework ReactionFrom User Action to Framework Reaction
From User Action to Framework Reaction
 
A Tour of the Modern Java Platform
A Tour of the Modern Java PlatformA Tour of the Modern Java Platform
A Tour of the Modern Java Platform
 
Java 9 Module System Introduction
Java 9 Module System IntroductionJava 9 Module System Introduction
Java 9 Module System Introduction
 
108 advancedjava
108 advancedjava108 advancedjava
108 advancedjava
 
Angular Interview Questions & Answers
Angular Interview Questions & AnswersAngular Interview Questions & Answers
Angular Interview Questions & Answers
 
OpenDaylight and YANG
OpenDaylight and YANGOpenDaylight and YANG
OpenDaylight and YANG
 
The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...
The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...
The Making of the Oracle R2DBC Driver and How to Take Your Code from Synchron...
 
Java script session 3
Java script session 3Java script session 3
Java script session 3
 
How and why to upgrade to java 16 or 17
How and why to upgrade to java 16 or 17How and why to upgrade to java 16 or 17
How and why to upgrade to java 16 or 17
 
Workflow Yapceu2010
Workflow Yapceu2010Workflow Yapceu2010
Workflow Yapceu2010
 
Reactjs Introduction - Virtual DOM
Reactjs Introduction - Virtual DOMReactjs Introduction - Virtual DOM
Reactjs Introduction - Virtual DOM
 
8 Most Effective Node.js Tools for Developers
8 Most Effective Node.js Tools for Developers8 Most Effective Node.js Tools for Developers
8 Most Effective Node.js Tools for Developers
 
Gradle: The Build System you have been waiting for!
Gradle: The Build System you have been waiting for!Gradle: The Build System you have been waiting for!
Gradle: The Build System you have been waiting for!
 
Open Social Summit Korea
Open Social Summit KoreaOpen Social Summit Korea
Open Social Summit Korea
 

Ähnlich wie Type script

Ähnlich wie Type script (20)

Type script
Type scriptType script
Type script
 
Typescript for the programmers who like javascript
Typescript for the programmers who like javascriptTypescript for the programmers who like javascript
Typescript for the programmers who like javascript
 
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptxUnit 1 - TypeScript & Introduction to Angular CLI.pptx
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
 
Jscript part1
Jscript part1Jscript part1
Jscript part1
 
Getting started with typescript
Getting started with typescriptGetting started with typescript
Getting started with typescript
 
Benefits of Typescript.pptx
Benefits of Typescript.pptxBenefits of Typescript.pptx
Benefits of Typescript.pptx
 
Type script vs javascript come face to face in battleground
Type script vs javascript come face to face in battlegroundType script vs javascript come face to face in battleground
Type script vs javascript come face to face in battleground
 
An Introduction to TypeScript
An Introduction to TypeScriptAn Introduction to TypeScript
An Introduction to TypeScript
 
Dotnet basics
Dotnet basicsDotnet basics
Dotnet basics
 
TypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersTypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack Developers
 
1..Net Framework Architecture-(c#)
1..Net Framework Architecture-(c#)1..Net Framework Architecture-(c#)
1..Net Framework Architecture-(c#)
 
TypeScript, Dart, CoffeeScript and JavaScript Comparison
TypeScript, Dart, CoffeeScript and JavaScript ComparisonTypeScript, Dart, CoffeeScript and JavaScript Comparison
TypeScript, Dart, CoffeeScript and JavaScript Comparison
 
Moving From JavaScript to TypeScript: Things Developers Should Know
Moving From JavaScript to TypeScript: Things Developers Should KnowMoving From JavaScript to TypeScript: Things Developers Should Know
Moving From JavaScript to TypeScript: Things Developers Should Know
 
An Introduction to TypeScript: Definition, History, and Key Features
An Introduction to TypeScript: Definition, History, and Key FeaturesAn Introduction to TypeScript: Definition, History, and Key Features
An Introduction to TypeScript: Definition, History, and Key Features
 
What is TypeScript? It's Definition, History And Features
What is TypeScript? It's Definition, History And FeaturesWhat is TypeScript? It's Definition, History And Features
What is TypeScript? It's Definition, History And Features
 
Introduction to C3.net Architecture unit
Introduction to C3.net Architecture unitIntroduction to C3.net Architecture unit
Introduction to C3.net Architecture unit
 
TypeScript VS JavaScript.pptx
TypeScript VS JavaScript.pptxTypeScript VS JavaScript.pptx
TypeScript VS JavaScript.pptx
 
Nodejs
NodejsNodejs
Nodejs
 
(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net
 
Introducing type script
Introducing type scriptIntroducing type script
Introducing type script
 

Mehr von Mallikarjuna G D

Mehr von Mallikarjuna G D (20)

Bootstrap 5 ppt
Bootstrap 5 pptBootstrap 5 ppt
Bootstrap 5 ppt
 
CSS
CSSCSS
CSS
 
Spring andspringboot training
Spring andspringboot trainingSpring andspringboot training
Spring andspringboot training
 
Hibernate
HibernateHibernate
Hibernate
 
Jspprogramming
JspprogrammingJspprogramming
Jspprogramming
 
Servlet programming
Servlet programmingServlet programming
Servlet programming
 
Servlet programming
Servlet programmingServlet programming
Servlet programming
 
Mmg logistics edu-final
Mmg  logistics edu-finalMmg  logistics edu-final
Mmg logistics edu-final
 
Interview preparation net_asp_csharp
Interview preparation net_asp_csharpInterview preparation net_asp_csharp
Interview preparation net_asp_csharp
 
Interview preparation devops
Interview preparation devopsInterview preparation devops
Interview preparation devops
 
Interview preparation testing
Interview preparation testingInterview preparation testing
Interview preparation testing
 
Interview preparation data_science
Interview preparation data_scienceInterview preparation data_science
Interview preparation data_science
 
Interview preparation full_stack_java
Interview preparation full_stack_javaInterview preparation full_stack_java
Interview preparation full_stack_java
 
Enterprunership
EnterprunershipEnterprunership
Enterprunership
 
Angularj2.0
Angularj2.0Angularj2.0
Angularj2.0
 
Jenkins
JenkinsJenkins
Jenkins
 
Hadoop
HadoopHadoop
Hadoop
 
Digital marketing
Digital marketingDigital marketing
Digital marketing
 
Training
TrainingTraining
Training
 
Project excursion career_orientation
Project excursion career_orientationProject excursion career_orientation
Project excursion career_orientation
 

Kürzlich hochgeladen

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Kürzlich hochgeladen (20)

80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 

Type script

  • 1. 14 December 2017 www.snipe.co.in 1 SNIPE TEAM 12/14/2017
  • 4. TypeScript is a typed superset of JavaScript that compiles to plain JavaScript.  TypeScript is pure object oriented with classes, interfaces and statically typed like C# or Java.  The popular JavaScript framework Angular 2.0 is written in TypeScript.  Mastering TypeScript can help programmers to write object-oriented programs and have them compiled to JavaScript, both on server side and client side. 12/14/2017 4 INTRODUCTION
  • 5.  Anders Hejlsberg, lead architect of C# and worked on the development of TypeScript.  TypeScript was first made public in October 2012 (at version 0.8), after two years of internal development at Microsoft.  On 22 September 2016, TypeScript 2.0 was released. 12/14/2017 5 HISTORY
  • 6. TYPESCRIPT What is TypeScript? • TypeScript is a strongly typed, object oriented, compiled language. • TypeScript is both a language and a set of tools. • TypeScript is a typed superset of JavaScript compiled to JavaScript. • In other words, TypeScript is JavaScript plus some additional features. 12/14/2017 6 JAVASCRIPT
  • 7. The benefits of TypeScript include −  Compilation − JavaScript is an interpreted language. TypeScript will compile the code and generate compilation errors, if it finds some sort of syntax errors. This helps to highlight errors before the script is run.  Strong Static Typing − JavaScript is not strongly typed. TypeScript comes with an optional static typing and type inference system through the TLS (TypeScript Language Service). The type of a variable, declared with no type, may be inferred by the TLS based on its value.  TypeScript supports Object Oriented Programming concepts like classes, interfaces, inheritance, etc. 12/14/2017 7 WHY USE TYPESCRIPT?
  • 8. Features of TypeScript • TypeScript is just JavaScript. TypeScript starts with JavaScript and ends with JavaScript. Typescript adopts the basic building blocks of your program from JavaScript. Hence, you only need to know JavaScript to use TypeScript. All TypeScript code is converted into its JavaScript equivalent for the purpose of execution. • TypeScript supports other JS libraries. Compiled TypeScript can be consumed from any JavaScript code. TypeScript-generated JavaScript can reuse all of the existing JavaScript frameworks, tools, and libraries. • JavaScript is TypeScript. This means that any valid .js file can be renamed to .ts and compiled with other TypeScript files. • TypeScript is portable. TypeScript is portable across browsers, devices, and operating systems. It can run on any environment that JavaScript runs on. Unlike its counterparts, TypeScript doesn’t need a dedicated VM or a specific runtime environment to execute. 12/14/2017 8 FEATURES
  • 9.  The ECMAScript specification is a standardized specification of a scripting language. There are six editions of ECMA-262 published. Version 6 of the standard is codenamed "Harmony". TypeScript is aligned with the ECMAScript6 specification.  TypeScript adopts its basic language features from the ECMAScript5 specification, i.e., the official specification for JavaScript. TypeScript language features like Modules and class-based orientation are in line with the EcmaScript 6 specification. Additionally, TypeScript also embraces features like generics and type annotations that aren’t a part of the EcmaScript6 specification. 12/14/2017 9 TYPESCRIPT AND ECMASCRIPT ADDITIONAL FEATURES ECMASCRIPT5 ECMASCRIPT5 TYPESCRIPT
  • 10. TypeScript has the following three components:  Language − It comprises of the syntax, keywords, and type annotations.  Compiler − The TypeScript compiler (tsc) converts the instructions written in TypeScript to its JavaScript equivalent.  Language Service − The "Language Service" exposes an additional layer around the core compiler pipeline that are editor-like applications. The language service supports the common set of a typical editor operations like statement completions, signature help, code formatting and outlining, colorization, etc. 12/14/2017 10 COMPONENTS OF TYPESCRIPT
  • 11. 12/14/2017 11 COMPONENTS OF TYPESCRIPT Language service compiler
  • 12. Declaration Files  When a TypeScript script gets compiled, there is an option to generate a declaration file (with the extension .d.ts) that functions as an interface to the components in the compiled JavaScript.  The concept of declaration files is analogous to the concept of header files found in C/C++. The declaration files (files with .d.ts extension) provide intellisense for types, function calls, and variable support for JavaScript libraries like jQuery, MooTools, etc. 12/14/2017 12 DECLARATION FILES
  • 13. Local Environment Setup Typescript is an Open Source technology. It can run on any browser, any host, and any OS. You will need the following tools to write and test a Typescript program −  A Text Editor  The text editor helps you to write your source code. Examples of a few editors include Windows Notepad, Notepad++, Emacs, vim or vi, etc. Editors used may vary with Operating Systems.  The source files are typically named with the extension .ts 12/14/2017 13 ENVIRONMENT SETUP
  • 14. The TypeScript compiler is itself a .ts file compiled down to JavaScript (.js) file. The TSC (TypeScript Compiler) is a source-to-source compiler (transcompiler / transpiler).  The TSC generates a JavaScript version of the .ts file passed to it. In other words, the TSC produces an equivalent JavaScript source code from the Typescript file given as an input to it. This process is termed as transpilation.  However, the compiler rejects any raw JavaScript file passed to it. The compiler deals with only .ts or .d.ts files. 12/14/2017 14 ENVIRONMENT SETUP app.jstsc app.tsapp.ts
  • 15.  Installing Node.js  Node.js is an open source, cross-platform runtime environment for server-side JavaScript. Node.js is required to run JavaScript without a browser support. It uses Google V8 JavaScript engine to execute code. You may download Node.js source code or a pre-built installer for your platform.  Step 1 − Download and run the .msi installer for Node  Step 2 − To verify if the installation was successful, enter the command node –v in the terminal window.  Step 3 − Type the following command in the terminal window to install TypeScript.  npm install -g typescript 12/14/2017 15 ENVIRONMENT SETUP
  • 16. var message:string = "Hello World" console.log(message) 12/14/2017 16  Your First TypeScript Code  Let us start with the traditional “Hello World” example − BASIC SYNTAX //Generated by typescript 1.8.10 var message = "Hello World"; console.log(message);
  • 17. 12/14/2017 17 BASIC SYNTAX On compiling, it will generate following JavaScript code. //Generated by typescript 1.8.10 var message = "Hello World"; console.log(message);Line 1 declares a variable by the name message. Variables are a mechanism to store values in a program. Line 2 prints the variable’s value to the prompt. Here, console refers to the terminal window. The function log () is used to display text on the screen.
  • 18. Let us see how to compile and execute a TypeScript program using Visual Studio Code. Follow the steps given below −  Step 1 − Save the file with .ts extension. We shall save the file as Test.ts. The code editor marks errors in the code, if any, while you save it.  Step 2 − Right-click the TypeScript file under the Working Files option in VS Code’s Explore Pane. Select Open in Command Prompt option.  Step 3 − To compile the file use the following command on the terminal window.   Step 4 − The file is compiled to Test.js. To run the program written, type the following in the terminal. 12/14/2017 18 COMPILE AND EXECUTE A TYPESCRIPT PROGRAM tsc Test.ts node Test.js
  • 19. Test.ts class Greeting { greet():void { console.log("Hello World!!!") } } var obj = new Greeting(); obj.greet(); 12/14/2017 19 EXAMPLE Test.js var Greeting = /** @class */ (function () { function Greeting() { } Greeting.prototype.greet = function () { console.log("Hello World!!!"); }; return Greeting; }()); var obj = new Greeting(); obj.greet();
  • 20. TypeScript is object oriented JavaScript. TypeScript supports object-oriented programming features like classes, interfaces, etc. A class in terms of OOP is a blueprint for creating objects. A class encapsulates data for the object. Typescript gives built in support for this concept called class. Creating classes Use the class keyword to declare a class in TypeScript. The syntax for the same is given below − • Syntax: 12/14/2017 20 CLASSES class class_name { //class scope }
  • 21. Example: Declaring a class class Car { //field engine:string; //constructor constructor(engine:string ) { this.engine = engine } //function disp():void { console.log("Engine is : "+this.engine) } } 12/14/2017 21 CLASSES //Generated by typescript 1.8.10 var Car = (function () { //constructor function Car(engine) { this.engine = engine; } //function Car.prototype.disp = function () { console.log("Engine is : " + this.engine); }; return Car; }());
  • 22. A module is designed with the idea to organize code written in TypeScript. Modules are broadly divided into −  Internal Modules  External Modules Internal Module: Internal modules came in earlier version of Typescript. This was used to logically group classes, interfaces, functions into one unit and can be exported in another module. This logical grouping is named namespace in latest version of TypeScript. 12/14/2017 22 MODULES
  • 23. Internal Module Syntax: 12/14/2017 23 MODULES namespace snipe community{ export function add(x, y) { console.log(x + y);} } var snipe community; (function (snipe community){ function add(x, y) { console.log(x + y); } snipe community.add = add; })(snipe community || (snipe community = {})); JavaScript generated in both cases are same:
  • 24. External Module: External modules in TypeScript exists to specify and load dependencies between multiple external js files. If there is only one js file used, then external modules are not relevant. Traditionally dependency management between JavaScript files was done using browser script tags (<script></script>). Syntax- 12/14/2017 24 MODULES //FileName : SomeInterface.ts export interface SomeInterface { //code declarations }
  • 25. External Module: Example / IShape.ts export interface IShape { draw(); } // Circle.ts import shape = require("./IShape"); export class Circle implements shape.IShape { public draw() { console.log("Cirlce is drawn (external module)"); } } // Triangle.ts import shape = require("./IShape"); export class Triangle implements shape.IShape { public draw() { console.log("Triangle is drawn (external module)"); } } // TestShape.ts Import shape = require("./IShape"); import circle = require("./Circle"); import triangle = require("./Triangle"); function drawAllShapes(shapeToDraw: shape.IShape) { shapeToDraw.draw(); } drawAllShapes(new circle.Circle()); drawAllShapes(new triangle.Triangle()); 12/14/2017 25 MODULES
  • 26. The command to compile the main TypeScript file for AMD systems is − On compiling, it will generate following JavaScript code for AMD. File:IShape.js 12/14/2017 26 MODULES tsc --module amd TestShape.ts //Generated by typescript 1.8.10 define(["require", "exports"], function (require, exports) { });
  • 27. File:Circle.js 12/14/2017 27 MODULES define(["require", "exports"], function (require, exports) { var Circle = (function () { function Circle() { } Circle.prototype.draw = function () { console.log("Cirlce is drawn (external module)"); }; return Circle; })(); exports.Circle = Circle; });
  • 28. File:Triangle.js 12/14/2017 28 MODULES define(["require", "exports"], function (require, exports) { var Triangle = (function () { function Triangle() { } Triangle.prototype.draw=function () { console.log("Triangle is drawn (external module)"); }; return Triangle; })(); exports.Triangle = Triangle; });
  • 29. TypeScript lets you write JavaScript the way you really want to. TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. TypeScript is pure object oriented with classes, interfaces and statically typed like C# or Java. The popular JavaScript framework Angular 2.0 is written in TypeScript. Mastering TypeScript can help programmers to write object-oriented programs and have them compiled to JavaScript, both on server side and client side. 12/14/2017 29 CONCLUSION