SlideShare a Scribd company logo
1 of 143
Download to read offline
TypeScript Vs. ES6
www.lifemichael.com
All logos, trademarks and brand names used in this presentation belong to their respective owners. Haim Michael and Life
Michael are independent and not related, affiliated or connected with any of these respective owners or their technologies.
LifeMichael.com
AngularJS Meetup Zurich
© 2015 Haim Michael 20150807
Life Michael Introduction
 Snowboarding. Learning. Coding. Teaching. More than 18
years of practical experience.
LifeMichael.com
© 2015 Haim Michael 20150807
Life Michael Introduction
 Professional Certifications
Zend Certified Engineer in PHP
Certified Java Professional
Certified Java EE Web Component Developer
OMG Certified UML Professional
 MBA (cum laude) from Tel-Aviv University
Information Systems Management
LifeMichael.com
© 2015 Haim Michael 20150807
Life Michael Introduction
 Huge professional practical experience in software
development both for the server side (Java EE) and for
mobile telephones.
http://blog.lifemichael.com
Mainly During The Years 2001-2007
LifeMichael.com
© 2015 Haim Michael 20150807
Life Michael Introduction
 Delivering academic advanced courses in computer
science.
 Delivering professional courses in software development
companies world wide.
LifeMichael.com
© 2015 Haim Michael 20150807
Life Michael Introduction
 Developing one of the biggest free online courses website
for software development.
http://abelski.lifemichael.com
* More Than 200 Courses
* Thousands of Video Clips
* Thousands of Assignments
* Continuously Developed
LifeMichael.com
© 2015 Haim Michael 20150807
Life Michael Introduction
 Popular channel of professional video clips on YouTube.
http://www.youtube.com/lifemichael
* More Than 3 Million Views
* More Than 3000 Video Clips
* More Than 100 Playlists
* More Than 3000 Subscribers
LifeMichael.com
© 2015 Haim Michael 20150807
Life Michael Introduction
 Maintaining free professional communities on Facebook,
Linkedin and Google+ for continuous professional update!
http://www.lifemichael.com/en/communities
LifeMichael.com
© 2015 Haim Michael 20150807
Life Michael Introduction
 I enjoy sharing my knowledge and experience. Teaching
is my passion.
http://speakerpedia.com/speakers/life-michael
http://lanyrd.com/profile/lifemichael
Speakerpedia
LifeMichael.com
© 2015 Haim Michael 20150807
Table of Content
 Introduction
 Types
 Classes
 Inheritance
 Generics
 Interfaces
LifeMichael.com
 Enums
 Exceptions
 Decorators
 ES6 and ES7
 Conclusions
© 2015 Haim Michael 20150807
Introduction
LifeMichael.com
© 2015 Haim Michael 20150807
History
 The TypeScript programming language was developed by
Microsoft. It is an open source programming language.
 The code we write in TypeScript is compiled into
JavaScript, so we can basically use TypeScript wherever
we use JavaScript.
http://www.typescriptlang.org
LifeMichael.com
© 2015 Haim Michael 20150807
Superset of JavaScript
 TypeScript is a superset of JavaScript. It includes the
entire JavaScript programming language together with
additional capabilities.
 In general, nearly every code we can write in JavaScript
can be included in code we write in TypeScript.
LifeMichael.com
© 2015 Haim Michael 20150807
Typed Superset
 TypeScript adds the capability to code with types.
TypeScript allows us to define new classes and new
interfaces.
 TypeScript allows us to specify the type of each and
every variable and is even capable of interfering the type
by itself.
 TypeScript allows us to use JavaScript as if it was a
strictly type programming language.
LifeMichael.com
© 2015 Haim Michael 20150807
Large Applications
 TypeScript provides us with the required capabilities in
order to develop large scale applications using
JavaScript.
LifeMichael.com
© 2015 Haim Michael 20150807
Clean JavaScript
 Compiling TypeScript into JavaScript we get a clean
simple ES3 compliant code we can run in any web
browser, in any node.js environment or in any other ES3
compliant environment.
LifeMichael.com
© 2015 Haim Michael 20150807
Available IDEs
 The recommended IDEs include PHPStorm, WebStorm
and Visual Studio.
 The WebStorm IDE was developed specifically for
developing the client side (FED). The PHPStorm IDE
was developed specifically for PHP. The PHPStorm IDE
includes the WebStorm IDE. Therefore, the same
guidelines that apply for WebStorm should apply for
PHPStorm.
LifeMichael.com
© 2015 Haim Michael 20150807
Enabling the TypeScript Compiler
 In order to develop code in TypeScript using the
PHPStorm or the WebStorm IDE we should first access
the Default Preferences setting window, enable the
TypeSciprt compiler, specifying the node interpreter and
specify the main file we want to compile.
LifeMichael.com
© 2015 Haim Michael 20150807
Enabling the TypeScript Compiler
LifeMichael.com
© 2015 Haim Michael 20150807
The TypeScript File
 We write our code in TypeScript in a file with the ts
extension.
LifeMichael.com
© 2015 Haim Michael 20150807
The TypeScript File
LifeMichael.com
© 2015 Haim Michael 20150807
The TypeScript File
LifeMichael.com
© 2015 Haim Michael 20150807
The HTML Document
 We should develop HTML5 document that includes a
script element that refers a file with the 'js' extension. Its
name should be the same as the name of the TypeScript
file. The only difference should be the extension. The
extension should be 'js' instead of 'ts'.
LifeMichael.com
© 2015 Haim Michael 20150807
The HTML Document
LifeMichael.com
© 2015 Haim Michael 20150807
Changes in Code
 We can mark the track changes checkbox and changes
in our code will immediately initiate the compiler.
LifeMichael.com
© 2015 Haim Michael 20150807
Code Sample
class Rectangle
{
constructor( private width:number,
private height:number) {}
area()
{
return this.width*this.height;
}
}
var ob = new Rectangle(3,4);
document.write("area is "+ob.area());
LifeMichael.com
© 2015 Haim Michael 20150807
Code Sample
LifeMichael.com
© 2015 Haim Michael 20150807
Visual Studio
 Visual Studio support for TypeScript is immediate . We
don't need to set or configure anything.
LifeMichael.com
© 2015 Haim Michael 20150807
Visual Studio
LifeMichael.com
© 2015 Haim Michael 20150807
JavaScript Supported
 Writing code in TypeScript we can use the very same
JavaScript we already know. Apart of few cases there
shouldn't be any problem doing so.
LifeMichael.com
© 2013 Haim Michael
Google Trends Comparison
LifeMichael.com
© 2015 Haim Michael 20150807
Angular 2 Developers Preferences
LifeMichael.com
 The results of a survey that was taken by Angular 2 team.
http://angularjs.blogspot.co.il/2015/09/angular-2-survey-results.html
© 2015 Haim Michael 20150807
Types
LifeMichael.com
© 2015 Haim Michael 20150807
Type Annotation
 The type annotation we can add to a variable we define
should come after the variable identified and should be
preceded by a colon.
LifeMichael.com
© 2015 Haim Michael 20150807
Type Annotation
var id:number = 123123;
var name:string = "mosh";
var tall:boolean = true;
var dosomething:(a:number,b:number)=>number = function(a:number,b:number)
{
return a+b;
}
var names:string[] = ['dave','taly','anat'];
LifeMichael.com
© 2015 Haim Michael 20150807
Dynamic Type
 TypeScript is optionally statically typed programming
language. The types are checked in order to prevent
assignment of invalid values in term of their types. We
can optionally change the variable into a dynamic one.
LifeMichael.com
© 2015 Haim Michael 20150807
Dynamic Type
LifeMichael.com
© 2015 Haim Michael 20150807
Automatic Type Inferring
 When assigning a variable, that was just created, with a
value, the TypeScript execution environment
automatically identifies the type and from that moment
on the type of that variable is unchanged.
LifeMichael.com
© 2015 Haim Michael 20150807
Automatic Type Inferring
LifeMichael.com
© 2015 Haim Michael 20150807
Type Assertion
 When the assignment we try to complete fails due to
typing problem we can override the compiler by forcing a
type assertion.
LifeMichael.com
© 2015 Haim Michael 20150807
Type Assertion
class Person
{
id:number;
name:string;
}
class Student extends Person
{
average:number;
}
var a:Person = new Student();
var b:Student = <Student>a;
LifeMichael.com
© 2015 Haim Michael 20150807
Type Inference
 When assigning a variable, that wasn't annotated with a
specific type, with a value the compiler automatically
inference the type.
function printDetails(f)
{
document.write(f('abc'));
}
printDetails(function(str)
{
return "# "+str+" #";
});
LifeMichael.com
© 2015 Haim Michael 20150807
Type Erasure
 When compiling the TypeScript code into JavaScript all
of the type annotations are removed.
var a:number = 3;
var b:string = 'abc';
var a = 3;
var b = 'abc';
LifeMichael.com
© 2015 Haim Michael 20150807
Classes
LifeMichael.com
© 2015 Haim Michael 20150807
Introduction
 TypeScript supports many of the object oriented
programming features we know from other
programming languages.
LifeMichael.com
© 2015 Haim Michael 20150807
The Constructor
 When we define a new class it automatically has a
constructor. The default one. We can define a new
constructor. When doing so, the default one will be
deleted.
LifeMichael.com
© 2015 Haim Michael 20150807
The Constructor
class Rectangle
{
private width:number;
private height:number;
constructor( w:number,
h:number)
{
this.setWidtht(w);
this.setHeight(h);
}
setWidtht(num:number):void
{
if(num>0)
{
this.width = num;
}
}
LifeMichael.com
© 2015 Haim Michael 20150807
The Constructor
setHeight(num:number):void
{
if(num>0)
{
this.height = num;
}
}
area()
{
return this.width*this.height;
}
}
LifeMichael.com
© 2015 Haim Michael 20150807
The Constructor
var rectangles:Array<Rectangle> =
new Array<Rectangle>();
rectangles[0] = new Rectangle(3,4);
rectangles[1] = new Rectangle(5,7);
rectangles[2] = new Rectangle(8,2);
rectangles[3] = new Rectangle(1,2);
rectangles[4] = new Rectangle(8,12);
LifeMichael.com
© 2015 Haim Michael 20150807
The Constructor
rectangles.sort((a,b)=>{
if(a.area()==b.area())
return 0;
else
{
if(a.area()>b.area())
return 1;
else if(a.area()<b.area())
return -1;
}
})
for(var k in rectangles) {
document.write("<br/>"+rectangles[k].area());
}
LifeMichael.com
© 2015 Haim Michael 20150807
The Constructor
LifeMichael.com
© 2015 Haim Michael 20150807
The Constructor
 When we define a new constructor we can specify each
one of its parameters with an access modifier and by
doing so indirectly define those parameters as instance
variables.
LifeMichael.com
© 2015 Haim Michael 20150807
The Constructor
class Rectangle
{
constructor( private width:number,
private height:number) {}
area():number
{
return this.width*this.height;
}
}
var rec = new Rectangle(3,4);
document.write("<br/>area is "+rec.area());
LifeMichael.com
© 2015 Haim Michael 20150807
The Constructor
LifeMichael.com
© 2015 Haim Michael 20150807
Access Modifiers
 The available access modifiers are private,
public and protected. The public access
modifier is the default one. If we don't specify an
access modifier then it is public.
 When we define a function or a instance variable with
the protected access modifier it will be accessible
from within the very same class in which the function
or the variable were defined as well as from within
subclasses of that class.
LifeMichael.com
© 2015 Haim Michael 20150807
Access Modifiers
class Rectangle
{
constructor( protected width:number,
protected height:number) {}
protected area():number
{
return this.width*this.height;
}
}
LifeMichael.com
© 2015 Haim Michael 20150807
Access Modifiers
class MagicalRectangle extends Rectangle
{
public printDetails():void
{
document.write("<br/>width="+this.width);
document.write("<br/>height="+this.height);
document.write("<br/>area="+this.area());
}
}
var rec = new MagicalRectangle(30,42);
rec.printDetails();
LifeMichael.com
© 2015 Haim Michael 20150807
Access Modifiers
LifeMichael.com
© 2015 Haim Michael 20150807
Variables and Methods
 The variables are usually declared before the
constructor. Each variable definition includes three parts.
The optional access modifier, the identifier and the type
annotation.
 The functions are declared without using the function
keyword. We can precede the function name with an
access modifier and we can append the function
declaration with the type of its returned value.
LifeMichael.com
© 2015 Haim Michael 20150807
Variables and Methods
class Rectangle
{
private width:number;
Private height:number;
constructor( width:number,
height:number)
{
this.width = width;
this.height = height;
}
protected area():number
{
return this.width*this.height;
}
}
LifeMichael.com
© 2015 Haim Michael 20150807
Static Variables and Methods
 We can define static variables and static methods by
adding the static keyword. Accessing static
variables and methods is done using the name of the
class.
LifeMichael.com
© 2015 Haim Michael 20150807
Static Variables and Methods
class FinanceUtils
{
public static VAT = 0.18;
public static calculateTax(sum:number):number
{
return 0.25*sum;
}
public static calculateVAT(sum:number):number
{
return FinanceUtils.VAT*sum;
}
}
var price:number = 1020;
document.write("<br/>"+FinanceUtils.calculateVAT(price));
LifeMichael.com
© 2015 Haim Michael 20150807
Static Variables and Methods
LifeMichael.com
© 2015 Haim Michael 20150807
Inheritance
LifeMichael.com
© 2015 Haim Michael 20150807
Introduction
 Using the extends keyword we can define a class that
extends another class.
 Every method and every variable are inherited.
TypeScript doesn't support different types of inheritance.
LifeMichael.com
© 2015 Haim Michael 20150807
Inheritance Meaning
 Each and every variable that exists in objects
instantiated from the base class will be in each and
every object instantiated from the new class.
 Each and every method we can invoke on objects
instantiated from the base class will be available for
invocation on each and every object instantiated from
the new class.
LifeMichael.com
© 2015 Haim Michael 20150807
The super Keyword
 Using the super keyword we can invoke the constructor
that was defined in the base class from within the
constructor that was defined in the new class.
 Similarly to Java, C# and C++, when instantiating a class
the default constructor in the super class is called as
well. We can use the super keyword in order to invoke
another one instead.
LifeMichael.com
© 2015 Haim Michael 20150807
The super Keyword
 Using the super keyword we can invoke a method
version we override. This way we can define a method
that includes the execution of the code that belongs to
the version it overrides.
LifeMichael.com
© 2015 Haim Michael 20150807
The super Keyword
class Person
{
private _id:number;
private _name:string;
constructor(id:number, name:string)
{
this._id = id;
this._name = name;
}
details()
{
document.write(" id="+this._id);
document.write(" name="+this._name);
}
}
LifeMichael.com
© 2015 Haim Michael 20150807
The super Keyword
class Student extends Person
{
private _average:number;
constructor(id:number,name:string,average:number)
{
this._average = average;
super(id,name);
}
details()
{
super.details();
document.write(" average="+this._average);
}
}
var ob = new Student(123123,"dave",88);
ob.details();
LifeMichael.com
© 2015 Haim Michael 20150807
The super Keyword
LifeMichael.com
© 2015 Haim Michael 20150807
Generics
LifeMichael.com
© 2015 Haim Michael 20150807
Introduction
 Using generics we can define functions and classes
that will be reused in order to work with various
different types.
LifeMichael.com
© 2015 Haim Michael 20150807
Generics Class
 Whenever we instantiate a generic class we should
specify the missing type(s) in order to get a new object
specifically with the type(s) we specified.
LifeMichael.com
© 2015 Haim Michael 20150807
Generics Class
class MyStack<T>
{
private index:number = 0;
private vec:T[];
constructor(size:number)
{
this.vec = new Array<T>(size);
}
push(ob:T):void
{
this.vec[this.index] = ob;
this.index++;
}
pop():T
{
this.index--;
return this.vec[this.index];
}
}
LifeMichael.com
© 2015 Haim Michael 20150807
Generics Class
var stack = new MyStack<string>(10);
stack.push("haifa");
stack.push("jerusalem");
stack.push("rehovot");
var temp = stack.pop();
document.write("<br/>typeof(temp)="+typeof(temp));
document.write("<br/>temp="+temp);
LifeMichael.com
© 2015 Haim Michael 20150807
Generics Class
LifeMichael.com
© 2015 Haim Michael 20150807
Generic Function
 Whenever we call a generic function we should specify
the missing type(s).
LifeMichael.com
© 2015 Haim Michael 20150807
Generic Function
class MyStack<T>
{
private index:number = 0;
private vec:T[];
constructor(size:number)
{
this.vec = new Array<T>(size);
}
push(ob:T):void
{
this.vec[this.index] = ob;
this.index++;
}
pop():T
{
this.index--;
return this.vec[this.index];
}
}
LifeMichael.com
© 2015 Haim Michael 20150807
Generic Function
function createStack<T>(size:number):MyStack<T>
{
return new MyStack<T>(size);
}
var stack = createStack<string>(10);
stack.push("haifa");
stack.push("jerusalem");
stack.push("rehovot");
var temp = stack.pop();
document.write("<br/>typeof(temp)="+typeof(temp));
document.write("<br/>temp="+temp);
LifeMichael.com
© 2015 Haim Michael 20150807
Generic Function
LifeMichael.com
© 2015 Haim Michael 20150807
Generic Function
 We can use the type parameter when defining a
variable that its type is a function with a specific
signature.
function createStack<T>(size:number):MyStack<T>
{
return new MyStack<T>(size);
}
var func: <T>(n:number)=>MyStack<T>;
func = createStack;
var stack = func<string>(10);
LifeMichael.com
© 2015 Haim Michael 20150807
Generic Function
class MyStack<T>
{
private index:number = 0;
private vec:T[];
constructor(size:number)
{
this.vec = new Array<T>(size);
}
push(ob:T):void
{
this.vec[this.index] = ob;
this.index++;
}
pop():T
{
this.index--;
return this.vec[this.index];
}
}
LifeMichael.com
© 2015 Haim Michael 20150807
Generic Function
function createStack<T>(size:number):MyStack<T>
{
return new MyStack<T>(size);
}
var func: <T>(n:number)=>MyStack<T>;
func = createStack;
var stack = func<string>(10);
stack.push("haifa");
stack.push("jerusalem");
stack.push("rehovot");
var temp = stack.pop();
document.write("<br/>typeof(temp)="+typeof(temp));
document.write("<br/>temp="+temp);
LifeMichael.com
© 2015 Haim Michael 20150807
Generic Function
LifeMichael.com
© 2015 Haim Michael 20150807
Generic Constraints
 When using the parameter type we can specify
constraints in order to limit the range of possible types.
function calculateAverage<T extends Student>
(students:Array<T>):number
{
var sum:number = 0;
for(var i:number=0; i<students.length; i++)
{
sum += students[i].average();
}
var result = sum / students.length;
return result;
}
LifeMichael.com
© 2015 Haim Michael 20150807
Generic Constraints
function calculateAverage<T extends Student>
(students:Array<T>):number
{
var sum:number = 0;
for(var i:number=0; i<students.length; i++)
{
sum += students[i].average();
}
var result = sum / students.length;
return result;
}
LifeMichael.com
© 2015 Haim Michael 20150807
Generic Constraints
class Student
{
private _average:number;
private _id:number;
private _name:string;
constructor(id:number,name:string,average:number)
{
this._average = average;
this._id = id;
this._name = name;
}
average():number
{
return this._average;
}
}
var students = [new Student(123123,"dave",88),
new Student(234343,"ronen",92),
new Student(34234,"yael",82)];
var avg = calculateAverage(students);
document.write("average is "+avg);
LifeMichael.com
© 2015 Haim Michael 20150807
Generic Constraints
LifeMichael.com
© 2015 Haim Michael 20150807
Interfaces
LifeMichael.com
© 2015 Haim Michael 20150807
Introduction
 TypeScript allows us to define an interface. The
interface we define in TypeScript can be used for
various purposes. We define a new interface using the
interface keyword.
 The interface can include the definition of abstract
methods, properties (instance variables) and even a
constructor.
LifeMichael.com
© 2015 Haim Michael 20150807
Abstract Type
 We can define an interface and use it as an abstract type
a concrete class can implement.
© 2015 Haim Michael 20150807
Abstract Type
interface IPrintable
{
print():void;
}
function printObjects<T extends Iprintable>
(students:Array<T>):void
{
for(var i:number=0; i<students.length; i++)
{
students[i].print();
}
}
LifeMichael.com
© 2015 Haim Michael 20150807
Abstract Type
class Student implements IPrintable
{
private _average:number;
private _id:number;
private _name:string;
constructor(id:number,name:string,average:number)
{
this._average = average;
this._id = id;
this._name = name;
}
average():number
{
return this._average;
}
print():void
{
document.write("<br/>name="+this._name+" id="+
this._id+" average="+this._average);
}
}
LifeMichael.com
© 2015 Haim Michael 20150807
Abstract Type
var students = [ new Student(123123,"dave",88),
new Student(234343,"ronen",92),
new Student(34234,"yael",82)];
printObjects(students);
LifeMichael.com
© 2015 Haim Michael 20150807
Abstract Type
LifeMichael.com
© 2015 Haim Michael 20150807
Structure Definition
 We can define an interface and use it as a structure
other types will be based on.
 When defining a class that implements an interface
that includes variables definition the class will need to
define those variables as well.
LifeMichael.com
© 2015 Haim Michael 20150807
Structure Definition
interface ILocation
{
x:number;
y:number;
}
function distance(ob:ILocation):number
{
return Math.sqrt(ob.x*ob.x + ob.y*ob.y);
}
LifeMichael.com
© 2015 Haim Michael 20150807
Structure Definition
class House implements ILocation
{
x:number;
y:number;
address:string;
constructor(str:string,x:number,y:number)
{
this.address = str;
this.x = x;
this.y = y;
}
}
var temp = new House("herzel 102, rehovot",3,4);
document.write("distance is "+distance(temp))
LifeMichael.com
© 2015 Haim Michael 20150807
Structure Definition
LifeMichael.com
© 2015 Haim Michael 20150807
Optional Properties
 When we define an interface it is possible to specify
those properties the interface includes their definition
and their implementation isn't required by appending
their name with a question mark.
interface ILocation
{
x?:number;
y?:number;
}
LifeMichael.com
© 2015 Haim Michael 20150807
Optional Properties
interface ILocation
{
x?:number;
y?:number;
}
function distance(ob:ILocation):void
{
if(ob.x && ob.y)
{
document.write("distance is " +
Math.sqrt(ob.x * ob.x + ob.y * ob.y));
}
else
{
document.write("it isn't possible to calculate the distance");
}
}
LifeMichael.com
© 2015 Haim Michael 20150807
Optional Properties
class Tent implements ILocation
{
address:string;
constructor(str:string)
{
this.address = str;
}
}
var temp = new Tent("herzel 102, rehovot");
document.write("distance is "+distance(temp));
LifeMichael.com
© 2015 Haim Michael 20150807
Optional Properties
LifeMichael.com
© 2015 Haim Michael 20150807
Describing Function Type
 The interfaces we define in TypeScript are capable of
describing function types.
 In order to describe a function signature using an
interface we should describe that signature within the
body of the interface.
interface CalculateFunction
{
(a:number,b:number):number;
}
LifeMichael.com
© 2015 Haim Michael 20150807
Describing Function Type
interface CalculateFunction
{
(a:number,b:number):number;
}
function sum(a,b)
{
return a+b;
}
function multiply(a,b)
{
return a*b;
}
var f:CalculateFunction;
f=sum;
document.write("<br/>result is "+f(3,4));
f=multiply;
document.write("<br/>result is "+f(3,4));
LifeMichael.com
© 2015 Haim Michael 20150807
Describing Function Type
LifeMichael.com
© 2015 Haim Michael 20150807
Describing Array Types
 We can define an interface in order to describe an array
type in our program.
LifeMichael.com
© 2015 Haim Michael 20150807
Describing Array Types
interface RectanglesArray
{
[index: number]: Rectangle;
length:number;
}
class Rectangle
{
width:number;
height:number;
constructor(w:number, h:number)
{
this.width = w;
this.height = h;
}
area():number
{
return this.width*this.height;
}
}
LifeMichael.com
© 2015 Haim Michael 20150807
Describing Array Types
function calc(vec:RectanglesArray):number
{
var sum:number = 0;
for (var i = 0; i < vec.length; i++)
{
sum+= vec[i].area();
}
return sum;
}
var vec:RectanglesArray;
vec = [new Rectangle(3,4), new Rectangle(5,4), new
Rectangle(4,2)];
document.write("total areas is "+calc(vec));
LifeMichael.com
© 2015 Haim Michael 20150807
Describing Array Types
LifeMichael.com
© 2015 Haim Michael 20150807
Interfaces Inheritance
 We can define an interface that extends other
interfaces. Unlike classes inheritance, an interface can
extend multiple other interface.
LifeMichael.com
© 2015 Haim Michael 20150807
Interfaces Inheritance
interface IPrintable
{
print():void
}
interface ICompareable
{
compare(other:any)
}
interface IPoint
{
x:number;
y:number;
}
interface Bird extends IPoint,ICompareable,IPrintable {}
LifeMichael.com
© 2015 Haim Michael 20150807
Enum
LifeMichael.com
© 2015 Haim Michael 20150807
Introduction
 As with many other programming languages, TypeScript
allows us to create a new enum type, as a way for giving
more friendly names to sets of numeric values.
enum Month {January, February, March, April};
var a:Month = Month.January;
var b:Month = Month.February;
document.write("<br/>a="+a);
document.write("<br/>b="+b);
LifeMichael.com
© 2015 Haim Michael 20150807
The Numbering
 By default, the numbering starts at 0. We can change
that by setting the value of one of the enum members.
enum Month {January=1, February, March, April};
var a:Month = Month.January;
var b:Month = Month.February;
document.write("<br/>a="+a);
document.write("<br/>b="+b);
LifeMichael.com
© 2015 Haim Michael 20150807
The Corresponding Name
 When having a numeric value we can get its
corresponding name in a specific enum by treating the
enum as an array.
enum Month {January=1, February, March, April};
var a:Month = Month.January;
var b:Month = Month.February;
var str:string = Month[3];
document.write(str);
LifeMichael.com
© 2015 Haim Michael 20150807
Exceptions
LifeMichael.com
© 2015 Haim Michael 20150807
Introduction
 When the code in JavaScript encounters an exception
the details will be printed to the console. They won't be
shown in the web browser.
 We can handle those exceptions using the try & catch
statement.
LifeMichael.com
© 2015 Haim Michael 20150807
Exceptions Throwing
 In order to throw an exception we should use the throw
keyword and instantiate the relevant exception class.
function divide(a:number,b:number):number
{
if(b==0)
throw new MathException("you cannot divide by 0!");
return a/b;
}
LifeMichael.com
© 2015 Haim Michael 20150807
Custom Exception Type
 We can create a new customized exception type by
defining a new class that implements the Error
interface.
 The new class should include (at the minimum) the
definition for name and message variables.
 It will also be very useful to define the toString()
function.
LifeMichael.com
© 2015 Haim Michael 20150807
Custom Exception Type
class MathException implements Error
{
public name:string = "MathException";
constructor(public message:string) {}
toString()
{
return "("+this.name +","+this.message+")";
}
}
LifeMichael.com
© 2015 Haim Michael 20150807
The catch Statement
 In order to catch an exception we should use the try
and catch statement.
try
{
document.write("<br/>divide(3,5)="+divide(3,5));
document.write("<br/>divide(7,0)="+divide(7,0));
document.write("<br/>divide(3,5)="+divide(12,5));
}
catch(e)
{
document.write(e.message);
}
LifeMichael.com
© 2015 Haim Michael 20150807
The finally Block
 The finally block comes right after the catch statement.
The code we have inside the finally block is executed
no matter whether an exception took place or not.
try
{
document.write("<br/>divide(3,5)="+divide(3,5));
}
catch(e)
{
document.write(e.message);
}
finally
{
}
LifeMichael.com
© 2015 Haim Michael 20150807
Sample
class MathException implements Error
{
public name:string = "MathException";
constructor(public message:string) {}
toString()
{
return "("+this.name +","+this.message+")";
}
}
function divide(a:number,b:number):number
{
if(b==0)
throw new MathException("you cannot divide by 0!");
return a/b;
}
LifeMichael.com
© 2015 Haim Michael 20150807
Sample
try
{
document.write("<br/>divide(3,5)="+divide(3,5));
document.write("<br/>divide(7,0)="+divide(7,0));
document.write("<br/>divide(3,5)="+divide(12,5));
}
catch(e)
{
document.write("<br/>"+e.message);
}
finally
{
document.write("<br/>finally always works!");
}
LifeMichael.com
© 2015 Haim Michael 20150807
Sample
LifeMichael.com
© 2015 Haim Michael 20150807
Decorators
LifeMichael.com
© 2015 Haim Michael 20150807
Decorators Development
 We can develop our own decorators (also known as
annotations in Java and as attributes in C#).
 The use of decorators when using Angular 2 simplifies the
development process and contributes to the code clarity.
LifeMichael.com
© 2015 Haim Michael 20150807
Decorators Development
LifeMichael.com
function AppComponent() {}
AppComponent.annotations = [
new angular.ComponentAnnotation({
selector: 'my-application'
}),
new angular.ViewAnnotation({
template: '<h1>Hello Friends:)</h1>'
})
];
document.addEventListener('DOMContentLoaded', function() {
angular.bootstrap(AppComponent);
});
Angular 2 in ES5
© 2015 Haim Michael 20150807
Decorators Development
LifeMichael.com
Angular 2 in TypeScript
@Component({
selector: 'hello'
})
@View({
template: `
<div>
Shalom World!
</div>
`
})
class AppComponent {
//...
}
bootstrap(AppComponent);
© 2015 Haim Michael 20150807
ES6 and ES7
LifeMichael.com
© 2015 Haim Michael 20150807
ES6 and ES7 Capabilities
 TypeScript transpiler already support most of ES6 and ES7
capabilities, allowing us to take advantage of them in a fairly
simple way.
http://kangax.github.io/compat-table/es7/
LifeMichael.com
© 2015 Haim Michael 20150807
ECMAScript 2015 (ES6)
 The main capabilities introduced in ES6 include the
following: Classes, Lambda Expressions (Arrow
Functions), Objects Literals Additional Possibilities,
Template Strings, Destructuring, Functions Definition new
Capabilities, The let and const Keywords, Symbols,
Iterators, Generators, Modules, Data Structures, Proxies,
Promises and Reflection.
LifeMichael.com
© 2015 Haim Michael 20150807
ECMAScript 2015 (ES6)
LifeMichael.com
© 2015 Haim Michael 20150807
ECMAScript 2016 (ES7)
 ES7 is currently under development. So far there are very
few features that were already finalized.
LifeMichael.com
© 2015 Haim Michael 20150807
ES6 and ES7 Capabilities
LifeMichael.com
© 2015 Haim Michael 20150807
Conclusion
LifeMichael.com
© 2013 Haim Michael
Languages Comparison
LifeMichael.com
Easy Difficult
Learning Curve
Popularity
SmallBig
Dart
TS
ES5
ES6
© 2013 Haim Michael
Languages Comparison
LifeMichael.com
Low High
Functional Programming Capabilities
OOPCapabilities
SmallBig
Dart
classes
abstract classes
TS
classes
interfaces
ES5
ES6
classes
© 2013 Haim Michael
Languages Comparison
LifeMichael.com
Low High
Annotation Development Support
GenericsSupport
SmallBig
Dart TS
ES5
ES6
© 2013 Haim Michael
Languages Comparison
LifeMichael.com
Not Available Available
Independent Virtual Machine
ServerDevelopmentSupport
LowHigh
Dart
TSES5ES6
© 2013 Haim Michael 20150815
Questions & Answers
Thanks for Attending My Talk!
If you liked it, please write me some feedback
at speakerpedia.com/speakers/life-michael
LifeMichael.com

More Related Content

What's hot

The WebView Role in Hybrid Applications
The WebView Role in Hybrid ApplicationsThe WebView Role in Hybrid Applications
The WebView Role in Hybrid ApplicationsHaim Michael
 
Top 10 open source technologies for enterprise/Business web application devel...
Top 10 open source technologies for enterprise/Business web application devel...Top 10 open source technologies for enterprise/Business web application devel...
Top 10 open source technologies for enterprise/Business web application devel...Techcronus Business Solutions Pvt. Ltd.
 
Practice Area - Application Development - Selling To Enterprise
Practice Area - Application Development - Selling To EnterprisePractice Area - Application Development - Selling To Enterprise
Practice Area - Application Development - Selling To EnterpriseChetan Sharma
 
Making sense of the front-end, for PHP developers
Making sense of the front-end, for PHP developersMaking sense of the front-end, for PHP developers
Making sense of the front-end, for PHP developersLewiz
 
English Resume - Glaucia Lemos
English Resume - Glaucia LemosEnglish Resume - Glaucia Lemos
English Resume - Glaucia LemosGlaucia Lemos
 
9 Useful Things that Every Web Developer Needs to Know
9 Useful Things that Every Web Developer Needs to Know9 Useful Things that Every Web Developer Needs to Know
9 Useful Things that Every Web Developer Needs to KnowSimobo
 
Top 10 Front End Development Technologies to Focus in 2018
Top 10 Front End Development Technologies to Focus in 2018Top 10 Front End Development Technologies to Focus in 2018
Top 10 Front End Development Technologies to Focus in 2018Helios Solutions
 
SynapseIndia gives an overview on comparison in PHP & ASP.NET in Terms of Cos...
SynapseIndia gives an overview on comparison in PHP & ASP.NET in Terms of Cos...SynapseIndia gives an overview on comparison in PHP & ASP.NET in Terms of Cos...
SynapseIndia gives an overview on comparison in PHP & ASP.NET in Terms of Cos...SynapseIndia
 
Web development tool
Web development toolWeb development tool
Web development toolDeep Bhavsar
 
Domain-driven design
Domain-driven designDomain-driven design
Domain-driven designKnoldus Inc.
 
Delhi student's day
Delhi student's dayDelhi student's day
Delhi student's dayAnkur Mishra
 
Porting business apps to Windows Phone
Porting business apps to Windows PhonePorting business apps to Windows Phone
Porting business apps to Windows PhoneMichele Capra
 
Arkhitech - who we are and what we do
Arkhitech - who we are and what we doArkhitech - who we are and what we do
Arkhitech - who we are and what we doSimobo
 
Javascript
JavascriptJavascript
JavascriptSushma M
 

What's hot (17)

The WebView Role in Hybrid Applications
The WebView Role in Hybrid ApplicationsThe WebView Role in Hybrid Applications
The WebView Role in Hybrid Applications
 
Top 10 open source technologies for enterprise/Business web application devel...
Top 10 open source technologies for enterprise/Business web application devel...Top 10 open source technologies for enterprise/Business web application devel...
Top 10 open source technologies for enterprise/Business web application devel...
 
Vaadin Jump Start
Vaadin Jump StartVaadin Jump Start
Vaadin Jump Start
 
Practice Area - Application Development - Selling To Enterprise
Practice Area - Application Development - Selling To EnterprisePractice Area - Application Development - Selling To Enterprise
Practice Area - Application Development - Selling To Enterprise
 
Making sense of the front-end, for PHP developers
Making sense of the front-end, for PHP developersMaking sense of the front-end, for PHP developers
Making sense of the front-end, for PHP developers
 
English Resume - Glaucia Lemos
English Resume - Glaucia LemosEnglish Resume - Glaucia Lemos
English Resume - Glaucia Lemos
 
9 Useful Things that Every Web Developer Needs to Know
9 Useful Things that Every Web Developer Needs to Know9 Useful Things that Every Web Developer Needs to Know
9 Useful Things that Every Web Developer Needs to Know
 
Top 10 Front End Development Technologies to Focus in 2018
Top 10 Front End Development Technologies to Focus in 2018Top 10 Front End Development Technologies to Focus in 2018
Top 10 Front End Development Technologies to Focus in 2018
 
SynapseIndia gives an overview on comparison in PHP & ASP.NET in Terms of Cos...
SynapseIndia gives an overview on comparison in PHP & ASP.NET in Terms of Cos...SynapseIndia gives an overview on comparison in PHP & ASP.NET in Terms of Cos...
SynapseIndia gives an overview on comparison in PHP & ASP.NET in Terms of Cos...
 
Html5 intro
Html5 introHtml5 intro
Html5 intro
 
Web development tool
Web development toolWeb development tool
Web development tool
 
Domain-driven design
Domain-driven designDomain-driven design
Domain-driven design
 
Delhi student's day
Delhi student's dayDelhi student's day
Delhi student's day
 
Porting business apps to Windows Phone
Porting business apps to Windows PhonePorting business apps to Windows Phone
Porting business apps to Windows Phone
 
Introduction to Java Scripting
Introduction to Java ScriptingIntroduction to Java Scripting
Introduction to Java Scripting
 
Arkhitech - who we are and what we do
Arkhitech - who we are and what we doArkhitech - who we are and what we do
Arkhitech - who we are and what we do
 
Javascript
JavascriptJavascript
Javascript
 

Similar to Typescript vas ES6

OOP Best Practices in JavaScript
OOP Best Practices in JavaScriptOOP Best Practices in JavaScript
OOP Best Practices in JavaScriptHaim Michael
 
Unit Testing in Python
Unit Testing in PythonUnit Testing in Python
Unit Testing in PythonHaim Michael
 
Test-Driven Development for Embedded C -- OOP Conference 2015, Munich
Test-Driven Development for Embedded C -- OOP Conference 2015, MunichTest-Driven Development for Embedded C -- OOP Conference 2015, Munich
Test-Driven Development for Embedded C -- OOP Conference 2015, MunichJames Grenning
 
Python Crash Course
Python Crash CoursePython Crash Course
Python Crash CourseHaim Michael
 
ASP.NET 5: What's the Big Deal
ASP.NET 5: What's the Big DealASP.NET 5: What's the Big Deal
ASP.NET 5: What's the Big DealJim Duffy
 
"Top Tips for Maximizing Tealium iQ" - First Data + WAD, Digital Velocity 2015
"Top Tips for Maximizing Tealium iQ" - First Data + WAD, Digital Velocity 2015"Top Tips for Maximizing Tealium iQ" - First Data + WAD, Digital Velocity 2015
"Top Tips for Maximizing Tealium iQ" - First Data + WAD, Digital Velocity 2015Tealium
 
Going Agile in a Multi-National Work Environment and the Tool We Chose
Going Agile in a Multi-National Work Environment and the Tool We ChoseGoing Agile in a Multi-National Work Environment and the Tool We Chose
Going Agile in a Multi-National Work Environment and the Tool We ChosePaula Stern
 
Programming in Python on Steroid
Programming in Python on SteroidProgramming in Python on Steroid
Programming in Python on SteroidHaim Michael
 
Bootstrap Crash Course 20180717
Bootstrap Crash Course 20180717Bootstrap Crash Course 20180717
Bootstrap Crash Course 20180717Haim Michael
 
Functional programming in Java
Functional programming in Java  Functional programming in Java
Functional programming in Java Haim Michael
 
JIOWA Code Generation Framework & Template Engine
JIOWA Code Generation Framework & Template EngineJIOWA Code Generation Framework & Template Engine
JIOWA Code Generation Framework & Template EngineRobert Mencl
 
Webinar on How to use MyAppConverter
Webinar on How to use  MyAppConverterWebinar on How to use  MyAppConverter
Webinar on How to use MyAppConverterJaoued Ahmed
 
To Microservices and Beyond
To Microservices and BeyondTo Microservices and Beyond
To Microservices and BeyondMatt Stine
 
MARISA SAWATPHADUNGKIJ
MARISA SAWATPHADUNGKIJMARISA SAWATPHADUNGKIJ
MARISA SAWATPHADUNGKIJAlisha Kapoor
 
Java11 New Features
Java11 New FeaturesJava11 New Features
Java11 New FeaturesHaim Michael
 
Bringing Partners, Teams & Systems Together through APIs
Bringing Partners, Teams & Systems Together through APIsBringing Partners, Teams & Systems Together through APIs
Bringing Partners, Teams & Systems Together through APIsApigee | Google Cloud
 
Knockout, TypeScript, and Nested Grids, Oh My!
Knockout, TypeScript, and Nested Grids, Oh My!Knockout, TypeScript, and Nested Grids, Oh My!
Knockout, TypeScript, and Nested Grids, Oh My!Sam Larko
 
Vertafore: Database Evaluation - Selecting Apache Cassandra
Vertafore: Database Evaluation - Selecting Apache CassandraVertafore: Database Evaluation - Selecting Apache Cassandra
Vertafore: Database Evaluation - Selecting Apache CassandraDataStax Academy
 

Similar to Typescript vas ES6 (20)

OOP Best Practices in JavaScript
OOP Best Practices in JavaScriptOOP Best Practices in JavaScript
OOP Best Practices in JavaScript
 
Unit Testing in Python
Unit Testing in PythonUnit Testing in Python
Unit Testing in Python
 
Test-Driven Development for Embedded C -- OOP Conference 2015, Munich
Test-Driven Development for Embedded C -- OOP Conference 2015, MunichTest-Driven Development for Embedded C -- OOP Conference 2015, Munich
Test-Driven Development for Embedded C -- OOP Conference 2015, Munich
 
Python Jump Start
Python Jump StartPython Jump Start
Python Jump Start
 
Python Jump Start
Python Jump StartPython Jump Start
Python Jump Start
 
Python Crash Course
Python Crash CoursePython Crash Course
Python Crash Course
 
ASP.NET 5: What's the Big Deal
ASP.NET 5: What's the Big DealASP.NET 5: What's the Big Deal
ASP.NET 5: What's the Big Deal
 
"Top Tips for Maximizing Tealium iQ" - First Data + WAD, Digital Velocity 2015
"Top Tips for Maximizing Tealium iQ" - First Data + WAD, Digital Velocity 2015"Top Tips for Maximizing Tealium iQ" - First Data + WAD, Digital Velocity 2015
"Top Tips for Maximizing Tealium iQ" - First Data + WAD, Digital Velocity 2015
 
Going Agile in a Multi-National Work Environment and the Tool We Chose
Going Agile in a Multi-National Work Environment and the Tool We ChoseGoing Agile in a Multi-National Work Environment and the Tool We Chose
Going Agile in a Multi-National Work Environment and the Tool We Chose
 
Programming in Python on Steroid
Programming in Python on SteroidProgramming in Python on Steroid
Programming in Python on Steroid
 
Bootstrap Crash Course 20180717
Bootstrap Crash Course 20180717Bootstrap Crash Course 20180717
Bootstrap Crash Course 20180717
 
Functional programming in Java
Functional programming in Java  Functional programming in Java
Functional programming in Java
 
JIOWA Code Generation Framework & Template Engine
JIOWA Code Generation Framework & Template EngineJIOWA Code Generation Framework & Template Engine
JIOWA Code Generation Framework & Template Engine
 
Webinar on How to use MyAppConverter
Webinar on How to use  MyAppConverterWebinar on How to use  MyAppConverter
Webinar on How to use MyAppConverter
 
To Microservices and Beyond
To Microservices and BeyondTo Microservices and Beyond
To Microservices and Beyond
 
MARISA SAWATPHADUNGKIJ
MARISA SAWATPHADUNGKIJMARISA SAWATPHADUNGKIJ
MARISA SAWATPHADUNGKIJ
 
Java11 New Features
Java11 New FeaturesJava11 New Features
Java11 New Features
 
Bringing Partners, Teams & Systems Together through APIs
Bringing Partners, Teams & Systems Together through APIsBringing Partners, Teams & Systems Together through APIs
Bringing Partners, Teams & Systems Together through APIs
 
Knockout, TypeScript, and Nested Grids, Oh My!
Knockout, TypeScript, and Nested Grids, Oh My!Knockout, TypeScript, and Nested Grids, Oh My!
Knockout, TypeScript, and Nested Grids, Oh My!
 
Vertafore: Database Evaluation - Selecting Apache Cassandra
Vertafore: Database Evaluation - Selecting Apache CassandraVertafore: Database Evaluation - Selecting Apache Cassandra
Vertafore: Database Evaluation - Selecting Apache Cassandra
 

More from Haim Michael

Virtual Threads in Java
Virtual Threads in JavaVirtual Threads in Java
Virtual Threads in JavaHaim Michael
 
MongoDB Design Patterns
MongoDB Design PatternsMongoDB Design Patterns
MongoDB Design PatternsHaim Michael
 
Introduction to SQL Injections
Introduction to SQL InjectionsIntroduction to SQL Injections
Introduction to SQL InjectionsHaim Michael
 
Record Classes in Java
Record Classes in JavaRecord Classes in Java
Record Classes in JavaHaim Michael
 
Microservices Design Patterns
Microservices Design PatternsMicroservices Design Patterns
Microservices Design PatternsHaim Michael
 
Structural Pattern Matching in Python
Structural Pattern Matching in PythonStructural Pattern Matching in Python
Structural Pattern Matching in PythonHaim Michael
 
JavaScript Jump Start 20220214
JavaScript Jump Start 20220214JavaScript Jump Start 20220214
JavaScript Jump Start 20220214Haim Michael
 
Bootstrap Jump Start
Bootstrap Jump StartBootstrap Jump Start
Bootstrap Jump StartHaim Michael
 
What is new in PHP
What is new in PHPWhat is new in PHP
What is new in PHPHaim Michael
 
What is new in Python 3.9
What is new in Python 3.9What is new in Python 3.9
What is new in Python 3.9Haim Michael
 
The matplotlib Library
The matplotlib LibraryThe matplotlib Library
The matplotlib LibraryHaim Michael
 
Pandas meetup 20200908
Pandas meetup 20200908Pandas meetup 20200908
Pandas meetup 20200908Haim Michael
 
The num py_library_20200818
The num py_library_20200818The num py_library_20200818
The num py_library_20200818Haim Michael
 
Jupyter notebook 20200728
Jupyter notebook 20200728Jupyter notebook 20200728
Jupyter notebook 20200728Haim Michael
 
Node.js Crash Course (Jump Start)
Node.js Crash Course (Jump Start) Node.js Crash Course (Jump Start)
Node.js Crash Course (Jump Start) Haim Michael
 
The Power of Decorators in Python [Meetup]
The Power of Decorators in Python [Meetup]The Power of Decorators in Python [Meetup]
The Power of Decorators in Python [Meetup]Haim Michael
 
Asynchronous JavaScript Programming
Asynchronous JavaScript ProgrammingAsynchronous JavaScript Programming
Asynchronous JavaScript ProgrammingHaim Michael
 
WordPress Jump Start
WordPress Jump StartWordPress Jump Start
WordPress Jump StartHaim Michael
 

More from Haim Michael (20)

Anti Patterns
Anti PatternsAnti Patterns
Anti Patterns
 
Virtual Threads in Java
Virtual Threads in JavaVirtual Threads in Java
Virtual Threads in Java
 
MongoDB Design Patterns
MongoDB Design PatternsMongoDB Design Patterns
MongoDB Design Patterns
 
Introduction to SQL Injections
Introduction to SQL InjectionsIntroduction to SQL Injections
Introduction to SQL Injections
 
Record Classes in Java
Record Classes in JavaRecord Classes in Java
Record Classes in Java
 
Microservices Design Patterns
Microservices Design PatternsMicroservices Design Patterns
Microservices Design Patterns
 
Structural Pattern Matching in Python
Structural Pattern Matching in PythonStructural Pattern Matching in Python
Structural Pattern Matching in Python
 
Java Jump Start
Java Jump StartJava Jump Start
Java Jump Start
 
JavaScript Jump Start 20220214
JavaScript Jump Start 20220214JavaScript Jump Start 20220214
JavaScript Jump Start 20220214
 
Bootstrap Jump Start
Bootstrap Jump StartBootstrap Jump Start
Bootstrap Jump Start
 
What is new in PHP
What is new in PHPWhat is new in PHP
What is new in PHP
 
What is new in Python 3.9
What is new in Python 3.9What is new in Python 3.9
What is new in Python 3.9
 
The matplotlib Library
The matplotlib LibraryThe matplotlib Library
The matplotlib Library
 
Pandas meetup 20200908
Pandas meetup 20200908Pandas meetup 20200908
Pandas meetup 20200908
 
The num py_library_20200818
The num py_library_20200818The num py_library_20200818
The num py_library_20200818
 
Jupyter notebook 20200728
Jupyter notebook 20200728Jupyter notebook 20200728
Jupyter notebook 20200728
 
Node.js Crash Course (Jump Start)
Node.js Crash Course (Jump Start) Node.js Crash Course (Jump Start)
Node.js Crash Course (Jump Start)
 
The Power of Decorators in Python [Meetup]
The Power of Decorators in Python [Meetup]The Power of Decorators in Python [Meetup]
The Power of Decorators in Python [Meetup]
 
Asynchronous JavaScript Programming
Asynchronous JavaScript ProgrammingAsynchronous JavaScript Programming
Asynchronous JavaScript Programming
 
WordPress Jump Start
WordPress Jump StartWordPress Jump Start
WordPress Jump Start
 

Recently uploaded

Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 

Recently uploaded (20)

Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 

Typescript vas ES6

  • 1. TypeScript Vs. ES6 www.lifemichael.com All logos, trademarks and brand names used in this presentation belong to their respective owners. Haim Michael and Life Michael are independent and not related, affiliated or connected with any of these respective owners or their technologies. LifeMichael.com AngularJS Meetup Zurich
  • 2. © 2015 Haim Michael 20150807 Life Michael Introduction  Snowboarding. Learning. Coding. Teaching. More than 18 years of practical experience. LifeMichael.com
  • 3. © 2015 Haim Michael 20150807 Life Michael Introduction  Professional Certifications Zend Certified Engineer in PHP Certified Java Professional Certified Java EE Web Component Developer OMG Certified UML Professional  MBA (cum laude) from Tel-Aviv University Information Systems Management LifeMichael.com
  • 4. © 2015 Haim Michael 20150807 Life Michael Introduction  Huge professional practical experience in software development both for the server side (Java EE) and for mobile telephones. http://blog.lifemichael.com Mainly During The Years 2001-2007 LifeMichael.com
  • 5. © 2015 Haim Michael 20150807 Life Michael Introduction  Delivering academic advanced courses in computer science.  Delivering professional courses in software development companies world wide. LifeMichael.com
  • 6. © 2015 Haim Michael 20150807 Life Michael Introduction  Developing one of the biggest free online courses website for software development. http://abelski.lifemichael.com * More Than 200 Courses * Thousands of Video Clips * Thousands of Assignments * Continuously Developed LifeMichael.com
  • 7. © 2015 Haim Michael 20150807 Life Michael Introduction  Popular channel of professional video clips on YouTube. http://www.youtube.com/lifemichael * More Than 3 Million Views * More Than 3000 Video Clips * More Than 100 Playlists * More Than 3000 Subscribers LifeMichael.com
  • 8. © 2015 Haim Michael 20150807 Life Michael Introduction  Maintaining free professional communities on Facebook, Linkedin and Google+ for continuous professional update! http://www.lifemichael.com/en/communities LifeMichael.com
  • 9. © 2015 Haim Michael 20150807 Life Michael Introduction  I enjoy sharing my knowledge and experience. Teaching is my passion. http://speakerpedia.com/speakers/life-michael http://lanyrd.com/profile/lifemichael Speakerpedia LifeMichael.com
  • 10. © 2015 Haim Michael 20150807 Table of Content  Introduction  Types  Classes  Inheritance  Generics  Interfaces LifeMichael.com  Enums  Exceptions  Decorators  ES6 and ES7  Conclusions
  • 11. © 2015 Haim Michael 20150807 Introduction LifeMichael.com
  • 12. © 2015 Haim Michael 20150807 History  The TypeScript programming language was developed by Microsoft. It is an open source programming language.  The code we write in TypeScript is compiled into JavaScript, so we can basically use TypeScript wherever we use JavaScript. http://www.typescriptlang.org LifeMichael.com
  • 13. © 2015 Haim Michael 20150807 Superset of JavaScript  TypeScript is a superset of JavaScript. It includes the entire JavaScript programming language together with additional capabilities.  In general, nearly every code we can write in JavaScript can be included in code we write in TypeScript. LifeMichael.com
  • 14. © 2015 Haim Michael 20150807 Typed Superset  TypeScript adds the capability to code with types. TypeScript allows us to define new classes and new interfaces.  TypeScript allows us to specify the type of each and every variable and is even capable of interfering the type by itself.  TypeScript allows us to use JavaScript as if it was a strictly type programming language. LifeMichael.com
  • 15. © 2015 Haim Michael 20150807 Large Applications  TypeScript provides us with the required capabilities in order to develop large scale applications using JavaScript. LifeMichael.com
  • 16. © 2015 Haim Michael 20150807 Clean JavaScript  Compiling TypeScript into JavaScript we get a clean simple ES3 compliant code we can run in any web browser, in any node.js environment or in any other ES3 compliant environment. LifeMichael.com
  • 17. © 2015 Haim Michael 20150807 Available IDEs  The recommended IDEs include PHPStorm, WebStorm and Visual Studio.  The WebStorm IDE was developed specifically for developing the client side (FED). The PHPStorm IDE was developed specifically for PHP. The PHPStorm IDE includes the WebStorm IDE. Therefore, the same guidelines that apply for WebStorm should apply for PHPStorm. LifeMichael.com
  • 18. © 2015 Haim Michael 20150807 Enabling the TypeScript Compiler  In order to develop code in TypeScript using the PHPStorm or the WebStorm IDE we should first access the Default Preferences setting window, enable the TypeSciprt compiler, specifying the node interpreter and specify the main file we want to compile. LifeMichael.com
  • 19. © 2015 Haim Michael 20150807 Enabling the TypeScript Compiler LifeMichael.com
  • 20. © 2015 Haim Michael 20150807 The TypeScript File  We write our code in TypeScript in a file with the ts extension. LifeMichael.com
  • 21. © 2015 Haim Michael 20150807 The TypeScript File LifeMichael.com
  • 22. © 2015 Haim Michael 20150807 The TypeScript File LifeMichael.com
  • 23. © 2015 Haim Michael 20150807 The HTML Document  We should develop HTML5 document that includes a script element that refers a file with the 'js' extension. Its name should be the same as the name of the TypeScript file. The only difference should be the extension. The extension should be 'js' instead of 'ts'. LifeMichael.com
  • 24. © 2015 Haim Michael 20150807 The HTML Document LifeMichael.com
  • 25. © 2015 Haim Michael 20150807 Changes in Code  We can mark the track changes checkbox and changes in our code will immediately initiate the compiler. LifeMichael.com
  • 26. © 2015 Haim Michael 20150807 Code Sample class Rectangle { constructor( private width:number, private height:number) {} area() { return this.width*this.height; } } var ob = new Rectangle(3,4); document.write("area is "+ob.area()); LifeMichael.com
  • 27. © 2015 Haim Michael 20150807 Code Sample LifeMichael.com
  • 28. © 2015 Haim Michael 20150807 Visual Studio  Visual Studio support for TypeScript is immediate . We don't need to set or configure anything. LifeMichael.com
  • 29. © 2015 Haim Michael 20150807 Visual Studio LifeMichael.com
  • 30. © 2015 Haim Michael 20150807 JavaScript Supported  Writing code in TypeScript we can use the very same JavaScript we already know. Apart of few cases there shouldn't be any problem doing so. LifeMichael.com
  • 31. © 2013 Haim Michael Google Trends Comparison LifeMichael.com
  • 32. © 2015 Haim Michael 20150807 Angular 2 Developers Preferences LifeMichael.com  The results of a survey that was taken by Angular 2 team. http://angularjs.blogspot.co.il/2015/09/angular-2-survey-results.html
  • 33. © 2015 Haim Michael 20150807 Types LifeMichael.com
  • 34. © 2015 Haim Michael 20150807 Type Annotation  The type annotation we can add to a variable we define should come after the variable identified and should be preceded by a colon. LifeMichael.com
  • 35. © 2015 Haim Michael 20150807 Type Annotation var id:number = 123123; var name:string = "mosh"; var tall:boolean = true; var dosomething:(a:number,b:number)=>number = function(a:number,b:number) { return a+b; } var names:string[] = ['dave','taly','anat']; LifeMichael.com
  • 36. © 2015 Haim Michael 20150807 Dynamic Type  TypeScript is optionally statically typed programming language. The types are checked in order to prevent assignment of invalid values in term of their types. We can optionally change the variable into a dynamic one. LifeMichael.com
  • 37. © 2015 Haim Michael 20150807 Dynamic Type LifeMichael.com
  • 38. © 2015 Haim Michael 20150807 Automatic Type Inferring  When assigning a variable, that was just created, with a value, the TypeScript execution environment automatically identifies the type and from that moment on the type of that variable is unchanged. LifeMichael.com
  • 39. © 2015 Haim Michael 20150807 Automatic Type Inferring LifeMichael.com
  • 40. © 2015 Haim Michael 20150807 Type Assertion  When the assignment we try to complete fails due to typing problem we can override the compiler by forcing a type assertion. LifeMichael.com
  • 41. © 2015 Haim Michael 20150807 Type Assertion class Person { id:number; name:string; } class Student extends Person { average:number; } var a:Person = new Student(); var b:Student = <Student>a; LifeMichael.com
  • 42. © 2015 Haim Michael 20150807 Type Inference  When assigning a variable, that wasn't annotated with a specific type, with a value the compiler automatically inference the type. function printDetails(f) { document.write(f('abc')); } printDetails(function(str) { return "# "+str+" #"; }); LifeMichael.com
  • 43. © 2015 Haim Michael 20150807 Type Erasure  When compiling the TypeScript code into JavaScript all of the type annotations are removed. var a:number = 3; var b:string = 'abc'; var a = 3; var b = 'abc'; LifeMichael.com
  • 44. © 2015 Haim Michael 20150807 Classes LifeMichael.com
  • 45. © 2015 Haim Michael 20150807 Introduction  TypeScript supports many of the object oriented programming features we know from other programming languages. LifeMichael.com
  • 46. © 2015 Haim Michael 20150807 The Constructor  When we define a new class it automatically has a constructor. The default one. We can define a new constructor. When doing so, the default one will be deleted. LifeMichael.com
  • 47. © 2015 Haim Michael 20150807 The Constructor class Rectangle { private width:number; private height:number; constructor( w:number, h:number) { this.setWidtht(w); this.setHeight(h); } setWidtht(num:number):void { if(num>0) { this.width = num; } } LifeMichael.com
  • 48. © 2015 Haim Michael 20150807 The Constructor setHeight(num:number):void { if(num>0) { this.height = num; } } area() { return this.width*this.height; } } LifeMichael.com
  • 49. © 2015 Haim Michael 20150807 The Constructor var rectangles:Array<Rectangle> = new Array<Rectangle>(); rectangles[0] = new Rectangle(3,4); rectangles[1] = new Rectangle(5,7); rectangles[2] = new Rectangle(8,2); rectangles[3] = new Rectangle(1,2); rectangles[4] = new Rectangle(8,12); LifeMichael.com
  • 50. © 2015 Haim Michael 20150807 The Constructor rectangles.sort((a,b)=>{ if(a.area()==b.area()) return 0; else { if(a.area()>b.area()) return 1; else if(a.area()<b.area()) return -1; } }) for(var k in rectangles) { document.write("<br/>"+rectangles[k].area()); } LifeMichael.com
  • 51. © 2015 Haim Michael 20150807 The Constructor LifeMichael.com
  • 52. © 2015 Haim Michael 20150807 The Constructor  When we define a new constructor we can specify each one of its parameters with an access modifier and by doing so indirectly define those parameters as instance variables. LifeMichael.com
  • 53. © 2015 Haim Michael 20150807 The Constructor class Rectangle { constructor( private width:number, private height:number) {} area():number { return this.width*this.height; } } var rec = new Rectangle(3,4); document.write("<br/>area is "+rec.area()); LifeMichael.com
  • 54. © 2015 Haim Michael 20150807 The Constructor LifeMichael.com
  • 55. © 2015 Haim Michael 20150807 Access Modifiers  The available access modifiers are private, public and protected. The public access modifier is the default one. If we don't specify an access modifier then it is public.  When we define a function or a instance variable with the protected access modifier it will be accessible from within the very same class in which the function or the variable were defined as well as from within subclasses of that class. LifeMichael.com
  • 56. © 2015 Haim Michael 20150807 Access Modifiers class Rectangle { constructor( protected width:number, protected height:number) {} protected area():number { return this.width*this.height; } } LifeMichael.com
  • 57. © 2015 Haim Michael 20150807 Access Modifiers class MagicalRectangle extends Rectangle { public printDetails():void { document.write("<br/>width="+this.width); document.write("<br/>height="+this.height); document.write("<br/>area="+this.area()); } } var rec = new MagicalRectangle(30,42); rec.printDetails(); LifeMichael.com
  • 58. © 2015 Haim Michael 20150807 Access Modifiers LifeMichael.com
  • 59. © 2015 Haim Michael 20150807 Variables and Methods  The variables are usually declared before the constructor. Each variable definition includes three parts. The optional access modifier, the identifier and the type annotation.  The functions are declared without using the function keyword. We can precede the function name with an access modifier and we can append the function declaration with the type of its returned value. LifeMichael.com
  • 60. © 2015 Haim Michael 20150807 Variables and Methods class Rectangle { private width:number; Private height:number; constructor( width:number, height:number) { this.width = width; this.height = height; } protected area():number { return this.width*this.height; } } LifeMichael.com
  • 61. © 2015 Haim Michael 20150807 Static Variables and Methods  We can define static variables and static methods by adding the static keyword. Accessing static variables and methods is done using the name of the class. LifeMichael.com
  • 62. © 2015 Haim Michael 20150807 Static Variables and Methods class FinanceUtils { public static VAT = 0.18; public static calculateTax(sum:number):number { return 0.25*sum; } public static calculateVAT(sum:number):number { return FinanceUtils.VAT*sum; } } var price:number = 1020; document.write("<br/>"+FinanceUtils.calculateVAT(price)); LifeMichael.com
  • 63. © 2015 Haim Michael 20150807 Static Variables and Methods LifeMichael.com
  • 64. © 2015 Haim Michael 20150807 Inheritance LifeMichael.com
  • 65. © 2015 Haim Michael 20150807 Introduction  Using the extends keyword we can define a class that extends another class.  Every method and every variable are inherited. TypeScript doesn't support different types of inheritance. LifeMichael.com
  • 66. © 2015 Haim Michael 20150807 Inheritance Meaning  Each and every variable that exists in objects instantiated from the base class will be in each and every object instantiated from the new class.  Each and every method we can invoke on objects instantiated from the base class will be available for invocation on each and every object instantiated from the new class. LifeMichael.com
  • 67. © 2015 Haim Michael 20150807 The super Keyword  Using the super keyword we can invoke the constructor that was defined in the base class from within the constructor that was defined in the new class.  Similarly to Java, C# and C++, when instantiating a class the default constructor in the super class is called as well. We can use the super keyword in order to invoke another one instead. LifeMichael.com
  • 68. © 2015 Haim Michael 20150807 The super Keyword  Using the super keyword we can invoke a method version we override. This way we can define a method that includes the execution of the code that belongs to the version it overrides. LifeMichael.com
  • 69. © 2015 Haim Michael 20150807 The super Keyword class Person { private _id:number; private _name:string; constructor(id:number, name:string) { this._id = id; this._name = name; } details() { document.write(" id="+this._id); document.write(" name="+this._name); } } LifeMichael.com
  • 70. © 2015 Haim Michael 20150807 The super Keyword class Student extends Person { private _average:number; constructor(id:number,name:string,average:number) { this._average = average; super(id,name); } details() { super.details(); document.write(" average="+this._average); } } var ob = new Student(123123,"dave",88); ob.details(); LifeMichael.com
  • 71. © 2015 Haim Michael 20150807 The super Keyword LifeMichael.com
  • 72. © 2015 Haim Michael 20150807 Generics LifeMichael.com
  • 73. © 2015 Haim Michael 20150807 Introduction  Using generics we can define functions and classes that will be reused in order to work with various different types. LifeMichael.com
  • 74. © 2015 Haim Michael 20150807 Generics Class  Whenever we instantiate a generic class we should specify the missing type(s) in order to get a new object specifically with the type(s) we specified. LifeMichael.com
  • 75. © 2015 Haim Michael 20150807 Generics Class class MyStack<T> { private index:number = 0; private vec:T[]; constructor(size:number) { this.vec = new Array<T>(size); } push(ob:T):void { this.vec[this.index] = ob; this.index++; } pop():T { this.index--; return this.vec[this.index]; } } LifeMichael.com
  • 76. © 2015 Haim Michael 20150807 Generics Class var stack = new MyStack<string>(10); stack.push("haifa"); stack.push("jerusalem"); stack.push("rehovot"); var temp = stack.pop(); document.write("<br/>typeof(temp)="+typeof(temp)); document.write("<br/>temp="+temp); LifeMichael.com
  • 77. © 2015 Haim Michael 20150807 Generics Class LifeMichael.com
  • 78. © 2015 Haim Michael 20150807 Generic Function  Whenever we call a generic function we should specify the missing type(s). LifeMichael.com
  • 79. © 2015 Haim Michael 20150807 Generic Function class MyStack<T> { private index:number = 0; private vec:T[]; constructor(size:number) { this.vec = new Array<T>(size); } push(ob:T):void { this.vec[this.index] = ob; this.index++; } pop():T { this.index--; return this.vec[this.index]; } } LifeMichael.com
  • 80. © 2015 Haim Michael 20150807 Generic Function function createStack<T>(size:number):MyStack<T> { return new MyStack<T>(size); } var stack = createStack<string>(10); stack.push("haifa"); stack.push("jerusalem"); stack.push("rehovot"); var temp = stack.pop(); document.write("<br/>typeof(temp)="+typeof(temp)); document.write("<br/>temp="+temp); LifeMichael.com
  • 81. © 2015 Haim Michael 20150807 Generic Function LifeMichael.com
  • 82. © 2015 Haim Michael 20150807 Generic Function  We can use the type parameter when defining a variable that its type is a function with a specific signature. function createStack<T>(size:number):MyStack<T> { return new MyStack<T>(size); } var func: <T>(n:number)=>MyStack<T>; func = createStack; var stack = func<string>(10); LifeMichael.com
  • 83. © 2015 Haim Michael 20150807 Generic Function class MyStack<T> { private index:number = 0; private vec:T[]; constructor(size:number) { this.vec = new Array<T>(size); } push(ob:T):void { this.vec[this.index] = ob; this.index++; } pop():T { this.index--; return this.vec[this.index]; } } LifeMichael.com
  • 84. © 2015 Haim Michael 20150807 Generic Function function createStack<T>(size:number):MyStack<T> { return new MyStack<T>(size); } var func: <T>(n:number)=>MyStack<T>; func = createStack; var stack = func<string>(10); stack.push("haifa"); stack.push("jerusalem"); stack.push("rehovot"); var temp = stack.pop(); document.write("<br/>typeof(temp)="+typeof(temp)); document.write("<br/>temp="+temp); LifeMichael.com
  • 85. © 2015 Haim Michael 20150807 Generic Function LifeMichael.com
  • 86. © 2015 Haim Michael 20150807 Generic Constraints  When using the parameter type we can specify constraints in order to limit the range of possible types. function calculateAverage<T extends Student> (students:Array<T>):number { var sum:number = 0; for(var i:number=0; i<students.length; i++) { sum += students[i].average(); } var result = sum / students.length; return result; } LifeMichael.com
  • 87. © 2015 Haim Michael 20150807 Generic Constraints function calculateAverage<T extends Student> (students:Array<T>):number { var sum:number = 0; for(var i:number=0; i<students.length; i++) { sum += students[i].average(); } var result = sum / students.length; return result; } LifeMichael.com
  • 88. © 2015 Haim Michael 20150807 Generic Constraints class Student { private _average:number; private _id:number; private _name:string; constructor(id:number,name:string,average:number) { this._average = average; this._id = id; this._name = name; } average():number { return this._average; } } var students = [new Student(123123,"dave",88), new Student(234343,"ronen",92), new Student(34234,"yael",82)]; var avg = calculateAverage(students); document.write("average is "+avg); LifeMichael.com
  • 89. © 2015 Haim Michael 20150807 Generic Constraints LifeMichael.com
  • 90. © 2015 Haim Michael 20150807 Interfaces LifeMichael.com
  • 91. © 2015 Haim Michael 20150807 Introduction  TypeScript allows us to define an interface. The interface we define in TypeScript can be used for various purposes. We define a new interface using the interface keyword.  The interface can include the definition of abstract methods, properties (instance variables) and even a constructor. LifeMichael.com
  • 92. © 2015 Haim Michael 20150807 Abstract Type  We can define an interface and use it as an abstract type a concrete class can implement.
  • 93. © 2015 Haim Michael 20150807 Abstract Type interface IPrintable { print():void; } function printObjects<T extends Iprintable> (students:Array<T>):void { for(var i:number=0; i<students.length; i++) { students[i].print(); } } LifeMichael.com
  • 94. © 2015 Haim Michael 20150807 Abstract Type class Student implements IPrintable { private _average:number; private _id:number; private _name:string; constructor(id:number,name:string,average:number) { this._average = average; this._id = id; this._name = name; } average():number { return this._average; } print():void { document.write("<br/>name="+this._name+" id="+ this._id+" average="+this._average); } } LifeMichael.com
  • 95. © 2015 Haim Michael 20150807 Abstract Type var students = [ new Student(123123,"dave",88), new Student(234343,"ronen",92), new Student(34234,"yael",82)]; printObjects(students); LifeMichael.com
  • 96. © 2015 Haim Michael 20150807 Abstract Type LifeMichael.com
  • 97. © 2015 Haim Michael 20150807 Structure Definition  We can define an interface and use it as a structure other types will be based on.  When defining a class that implements an interface that includes variables definition the class will need to define those variables as well. LifeMichael.com
  • 98. © 2015 Haim Michael 20150807 Structure Definition interface ILocation { x:number; y:number; } function distance(ob:ILocation):number { return Math.sqrt(ob.x*ob.x + ob.y*ob.y); } LifeMichael.com
  • 99. © 2015 Haim Michael 20150807 Structure Definition class House implements ILocation { x:number; y:number; address:string; constructor(str:string,x:number,y:number) { this.address = str; this.x = x; this.y = y; } } var temp = new House("herzel 102, rehovot",3,4); document.write("distance is "+distance(temp)) LifeMichael.com
  • 100. © 2015 Haim Michael 20150807 Structure Definition LifeMichael.com
  • 101. © 2015 Haim Michael 20150807 Optional Properties  When we define an interface it is possible to specify those properties the interface includes their definition and their implementation isn't required by appending their name with a question mark. interface ILocation { x?:number; y?:number; } LifeMichael.com
  • 102. © 2015 Haim Michael 20150807 Optional Properties interface ILocation { x?:number; y?:number; } function distance(ob:ILocation):void { if(ob.x && ob.y) { document.write("distance is " + Math.sqrt(ob.x * ob.x + ob.y * ob.y)); } else { document.write("it isn't possible to calculate the distance"); } } LifeMichael.com
  • 103. © 2015 Haim Michael 20150807 Optional Properties class Tent implements ILocation { address:string; constructor(str:string) { this.address = str; } } var temp = new Tent("herzel 102, rehovot"); document.write("distance is "+distance(temp)); LifeMichael.com
  • 104. © 2015 Haim Michael 20150807 Optional Properties LifeMichael.com
  • 105. © 2015 Haim Michael 20150807 Describing Function Type  The interfaces we define in TypeScript are capable of describing function types.  In order to describe a function signature using an interface we should describe that signature within the body of the interface. interface CalculateFunction { (a:number,b:number):number; } LifeMichael.com
  • 106. © 2015 Haim Michael 20150807 Describing Function Type interface CalculateFunction { (a:number,b:number):number; } function sum(a,b) { return a+b; } function multiply(a,b) { return a*b; } var f:CalculateFunction; f=sum; document.write("<br/>result is "+f(3,4)); f=multiply; document.write("<br/>result is "+f(3,4)); LifeMichael.com
  • 107. © 2015 Haim Michael 20150807 Describing Function Type LifeMichael.com
  • 108. © 2015 Haim Michael 20150807 Describing Array Types  We can define an interface in order to describe an array type in our program. LifeMichael.com
  • 109. © 2015 Haim Michael 20150807 Describing Array Types interface RectanglesArray { [index: number]: Rectangle; length:number; } class Rectangle { width:number; height:number; constructor(w:number, h:number) { this.width = w; this.height = h; } area():number { return this.width*this.height; } } LifeMichael.com
  • 110. © 2015 Haim Michael 20150807 Describing Array Types function calc(vec:RectanglesArray):number { var sum:number = 0; for (var i = 0; i < vec.length; i++) { sum+= vec[i].area(); } return sum; } var vec:RectanglesArray; vec = [new Rectangle(3,4), new Rectangle(5,4), new Rectangle(4,2)]; document.write("total areas is "+calc(vec)); LifeMichael.com
  • 111. © 2015 Haim Michael 20150807 Describing Array Types LifeMichael.com
  • 112. © 2015 Haim Michael 20150807 Interfaces Inheritance  We can define an interface that extends other interfaces. Unlike classes inheritance, an interface can extend multiple other interface. LifeMichael.com
  • 113. © 2015 Haim Michael 20150807 Interfaces Inheritance interface IPrintable { print():void } interface ICompareable { compare(other:any) } interface IPoint { x:number; y:number; } interface Bird extends IPoint,ICompareable,IPrintable {} LifeMichael.com
  • 114. © 2015 Haim Michael 20150807 Enum LifeMichael.com
  • 115. © 2015 Haim Michael 20150807 Introduction  As with many other programming languages, TypeScript allows us to create a new enum type, as a way for giving more friendly names to sets of numeric values. enum Month {January, February, March, April}; var a:Month = Month.January; var b:Month = Month.February; document.write("<br/>a="+a); document.write("<br/>b="+b); LifeMichael.com
  • 116. © 2015 Haim Michael 20150807 The Numbering  By default, the numbering starts at 0. We can change that by setting the value of one of the enum members. enum Month {January=1, February, March, April}; var a:Month = Month.January; var b:Month = Month.February; document.write("<br/>a="+a); document.write("<br/>b="+b); LifeMichael.com
  • 117. © 2015 Haim Michael 20150807 The Corresponding Name  When having a numeric value we can get its corresponding name in a specific enum by treating the enum as an array. enum Month {January=1, February, March, April}; var a:Month = Month.January; var b:Month = Month.February; var str:string = Month[3]; document.write(str); LifeMichael.com
  • 118. © 2015 Haim Michael 20150807 Exceptions LifeMichael.com
  • 119. © 2015 Haim Michael 20150807 Introduction  When the code in JavaScript encounters an exception the details will be printed to the console. They won't be shown in the web browser.  We can handle those exceptions using the try & catch statement. LifeMichael.com
  • 120. © 2015 Haim Michael 20150807 Exceptions Throwing  In order to throw an exception we should use the throw keyword and instantiate the relevant exception class. function divide(a:number,b:number):number { if(b==0) throw new MathException("you cannot divide by 0!"); return a/b; } LifeMichael.com
  • 121. © 2015 Haim Michael 20150807 Custom Exception Type  We can create a new customized exception type by defining a new class that implements the Error interface.  The new class should include (at the minimum) the definition for name and message variables.  It will also be very useful to define the toString() function. LifeMichael.com
  • 122. © 2015 Haim Michael 20150807 Custom Exception Type class MathException implements Error { public name:string = "MathException"; constructor(public message:string) {} toString() { return "("+this.name +","+this.message+")"; } } LifeMichael.com
  • 123. © 2015 Haim Michael 20150807 The catch Statement  In order to catch an exception we should use the try and catch statement. try { document.write("<br/>divide(3,5)="+divide(3,5)); document.write("<br/>divide(7,0)="+divide(7,0)); document.write("<br/>divide(3,5)="+divide(12,5)); } catch(e) { document.write(e.message); } LifeMichael.com
  • 124. © 2015 Haim Michael 20150807 The finally Block  The finally block comes right after the catch statement. The code we have inside the finally block is executed no matter whether an exception took place or not. try { document.write("<br/>divide(3,5)="+divide(3,5)); } catch(e) { document.write(e.message); } finally { } LifeMichael.com
  • 125. © 2015 Haim Michael 20150807 Sample class MathException implements Error { public name:string = "MathException"; constructor(public message:string) {} toString() { return "("+this.name +","+this.message+")"; } } function divide(a:number,b:number):number { if(b==0) throw new MathException("you cannot divide by 0!"); return a/b; } LifeMichael.com
  • 126. © 2015 Haim Michael 20150807 Sample try { document.write("<br/>divide(3,5)="+divide(3,5)); document.write("<br/>divide(7,0)="+divide(7,0)); document.write("<br/>divide(3,5)="+divide(12,5)); } catch(e) { document.write("<br/>"+e.message); } finally { document.write("<br/>finally always works!"); } LifeMichael.com
  • 127. © 2015 Haim Michael 20150807 Sample LifeMichael.com
  • 128. © 2015 Haim Michael 20150807 Decorators LifeMichael.com
  • 129. © 2015 Haim Michael 20150807 Decorators Development  We can develop our own decorators (also known as annotations in Java and as attributes in C#).  The use of decorators when using Angular 2 simplifies the development process and contributes to the code clarity. LifeMichael.com
  • 130. © 2015 Haim Michael 20150807 Decorators Development LifeMichael.com function AppComponent() {} AppComponent.annotations = [ new angular.ComponentAnnotation({ selector: 'my-application' }), new angular.ViewAnnotation({ template: '<h1>Hello Friends:)</h1>' }) ]; document.addEventListener('DOMContentLoaded', function() { angular.bootstrap(AppComponent); }); Angular 2 in ES5
  • 131. © 2015 Haim Michael 20150807 Decorators Development LifeMichael.com Angular 2 in TypeScript @Component({ selector: 'hello' }) @View({ template: ` <div> Shalom World! </div> ` }) class AppComponent { //... } bootstrap(AppComponent);
  • 132. © 2015 Haim Michael 20150807 ES6 and ES7 LifeMichael.com
  • 133. © 2015 Haim Michael 20150807 ES6 and ES7 Capabilities  TypeScript transpiler already support most of ES6 and ES7 capabilities, allowing us to take advantage of them in a fairly simple way. http://kangax.github.io/compat-table/es7/ LifeMichael.com
  • 134. © 2015 Haim Michael 20150807 ECMAScript 2015 (ES6)  The main capabilities introduced in ES6 include the following: Classes, Lambda Expressions (Arrow Functions), Objects Literals Additional Possibilities, Template Strings, Destructuring, Functions Definition new Capabilities, The let and const Keywords, Symbols, Iterators, Generators, Modules, Data Structures, Proxies, Promises and Reflection. LifeMichael.com
  • 135. © 2015 Haim Michael 20150807 ECMAScript 2015 (ES6) LifeMichael.com
  • 136. © 2015 Haim Michael 20150807 ECMAScript 2016 (ES7)  ES7 is currently under development. So far there are very few features that were already finalized. LifeMichael.com
  • 137. © 2015 Haim Michael 20150807 ES6 and ES7 Capabilities LifeMichael.com
  • 138. © 2015 Haim Michael 20150807 Conclusion LifeMichael.com
  • 139. © 2013 Haim Michael Languages Comparison LifeMichael.com Easy Difficult Learning Curve Popularity SmallBig Dart TS ES5 ES6
  • 140. © 2013 Haim Michael Languages Comparison LifeMichael.com Low High Functional Programming Capabilities OOPCapabilities SmallBig Dart classes abstract classes TS classes interfaces ES5 ES6 classes
  • 141. © 2013 Haim Michael Languages Comparison LifeMichael.com Low High Annotation Development Support GenericsSupport SmallBig Dart TS ES5 ES6
  • 142. © 2013 Haim Michael Languages Comparison LifeMichael.com Not Available Available Independent Virtual Machine ServerDevelopmentSupport LowHigh Dart TSES5ES6
  • 143. © 2013 Haim Michael 20150815 Questions & Answers Thanks for Attending My Talk! If you liked it, please write me some feedback at speakerpedia.com/speakers/life-michael LifeMichael.com