SlideShare a Scribd company logo
© 1996-2017 All Rights Reserved.
Advanced Topics
in TypeScript
Haim Michael
October 17st
, 2017
All logos, trade marks and brand names used in this presentation belong
to the respective owners.
lifemichael
You can watch the video at
https://youtu.be/lIbConUCkRs
TypeScript
© 1996-2017 All Rights Reserved.
Haim Michael Introduction
● Snowboarding. Learning. Coding. Teaching. More
than 16 years of Practical Experience.
lifemichael
© 1996-2017 All Rights Reserved.
Haim 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
© 1996-2017 All Rights Reserved.
Introduction
 “TypeScript is a typed superset of JavaScript
that compiles to plain JavaScript.”
www.typescriptlang.org
lifemichael
© 1996-2017 All Rights Reserved.
Fast Evolvement
 TypeScript evolves probably faster than any
other programming language.
12/10/2017 – 2.6rc
31/8/2017 – 2.5
27/6/2017 – 2.4
27/4/2017 – 2.3
22/2/2017 – 2.2
...
lifemichael
© 1996-2017 All Rights Reserved.
The // @ts-ignore Comment
 Using this comment (available as of 2.6) we can
suppress error messages.
lifemichael
if (false) {
//@ts-ignore
console.log("hello");
}
© 1996-2017 All Rights Reserved.
Localized Diagnostic Messages
 As of 2.6, we can add the --locale flag for
getting localized messages.
lifemichael
if (false) {
console.log("hello");
}
© 1996-2017 All Rights Reserved.
Optional catch clause Variable
 As of 2.5, we can avoid specifying a variable in
the catch clause.
lifemichael
let input = "...";
try {
JSON.parse(input);
}
catch {
console.log("invalid json:nn" +
input)
}
© 1996-2017 All Rights Reserved.
Anonymous Class Type
 As of 1.6 we can define a class without
specifying its name. We can write a class
expression, which is a class definition without
specifying its name.
 It is very similar to the possibility to define
anonymous function.
lifemichael
© 1996-2017 All Rights Reserved.
Anonymous Class Type
lifemichael
let Point = class {
Constructor(
public x: number,
public y: number) { }
public length() {
return Math.sqrt(
this.x * this.x + this.y * this.y);
}
};
var p = new Point(3, 4);
console.log(p.length());
© 1996-2017 All Rights Reserved.
Type Alias
 As of 1.4 we can define custom alias for types
that were already defined.
lifemichael
type Calc = ((a:number,b:number)=>number)
var f1:Calc = function(num1,num2){
return num1+num2;
}
var f2:Calc = function(num1,num2){
return num1*num2;
}
var temp = f1(45,5)
console.log(temp)
© 1996-2017 All Rights Reserved.
Type Alias
 As of 1.6 the type alias can be generic.
lifemichael
type Create<T> = (() => T);
var f3:Create<number> = function(){
return 12;
};
var f4:Create<string> = function(){
return "abc";
}
console.log(f4());
© 1996-2017 All Rights Reserved.
Union Types
 As of 1.4 we can combine multiple types into
one.
lifemichael
let destination:string|string[];
destination = "tel-aviv";
destination = ["tel-aviv","haifa","jerusalem"]
© 1996-2017 All Rights Reserved.
Union Types
lifemichael
interface IBook {
id: string;
pages: number;
}
interface INewspaper {
companyId: string;
}
type IPublication = IBook | INewspaper;
let ob: IPublication = {
id: 'ID3241',
pages: 21
};
© 1996-2017 All Rights Reserved.
Union Types
 We can use the same syntax for specifying that
the returned value of a specific function is either
of the first type or the second (or the third.. etc).
Doing so is known as types guarding.
lifemichael
© 1996-2017 All Rights Reserved.
Union Types
lifemichael
class Student{}
class Teacher{}
function getResponsible(n: number):
Student | Teacher {
if (n === 1) {
return new Teacher();
} else {
return new Student();
}
}
© 1996-2017 All Rights Reserved.
Accessors
 TypeScript allows us to define accessors, also
known as properties, in our code.
lifemichael
© 1996-2017 All Rights Reserved.
Accessors
lifemichael
class Rectangle
{
private _width:number;
private _height:number;
constructor(width: number, height: number) {
this._width = width;
this._height = height;
}
get width(): number {
return this._width;
}
set width(value: number) {
if(value>0) {
this._width = value;
}
}
© 1996-2017 All Rights Reserved.
get height(): number {
return this._height;
}
set height(value: number) {
this._height = value;
}
public area():number {
return this.height*this.width;
}
}
var rec:Rectangle = new Rectangle(4,5);
rec.width = 3;
document.write("area is "+rec.area());
Accessors
lifemichael
© 1996-2017 All Rights Reserved.
Optional Parameters
 Unlike JavaScript, when calling a function
passing over arguments the number of
arguments must match the number of the
parameters. If the number of arguments doesn't
match the number of parameters then we shall
get a compilation error.
lifemichael
© 1996-2017 All Rights Reserved.
Optional Parameters
 Adding the question mark to the name of a
parameter will turn that parameter into an
optional one.
 The parameters that are not optional are also
known as the required parameters. The required
parameters cannot come after the optional
ones.
lifemichael
© 1996-2017 All Rights Reserved.
Optional Parameters
 The optional parameters should be after any
other required one. They should be the last
ones.
lifemichael
© 1996-2017 All Rights Reserved.
Optional Parameters
lifemichael
function sum(a,b,c?)
{
var total = 0;
if(c!==undefined)
{
total += c;
}
total += (a+b);
return total;
}
var temp = sum(7,8);
document.write("temp="+temp);
© 1996-2017 All Rights Reserved.
Default Parameters
 When defining a function we can specify default
values for any of its parameters. Doing so, if an
argument is not passed over to the parameter
then the default value we specified will be set
instead.
 The default value we assign a parameter can be
the value of expression evaluated during
runtime.
lifemichael
© 1996-2017 All Rights Reserved.
Default Parameters
lifemichael
function dosomething(a,b,step=((b-a)%5))
{
var i=a;
while(a<=b)
{
document.write("<br/>"+a);
a+=step;
}
}
dosomething(1,20);
© 1996-2017 All Rights Reserved.
Rest Parameters
 The rest parameter is a parameter that when we
call the function we pass over zero or more
arguments of the specified type to it.
 Each function can include one rest parameter at
the most. We cannot have more than that.
 The type of the rest parameter must be the
array type.
lifemichael
© 1996-2017 All Rights Reserved.
Rest Parameters
 In order to define a rest parameter we just need
to prefix the parameter with three periods.
lifemichael
function sum(...numbers: number[]):number
{
var total:number = 0;
for(var i=0; i<numbers.length; i++)
{
total += numbers[i];
}
return total;
}
document.write("<br/>"+sum(2,5,3));
© 1996-2017 All Rights Reserved.
Generics Constraint
 When using the parameter type we can specify
constraints in order to limit the range of possible
types.
lifemichael
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;
}
© 1996-2017 All Rights Reserved.
Generics Constraint
lifemichael
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;
}
}
© 1996-2017 All Rights Reserved.
Describing Function Type
 We can use an interface for describing a
function type.
lifemichael
interface CalculateFunction
{
(a:number,b:number):number;
}
© 1996-2017 All Rights Reserved.
Describing Function Type
lifemichael
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));
© 1996-2017 All Rights Reserved.
Describing Array Type
 We can use an interface for describing an array
type.
lifemichael
interface RectanglesArray
{
[index: number]: Rectangle;
length:number;
}
© 1996-2017 All Rights Reserved.
Describing Array Type
lifemichael
class Rectangle
{
width:number;
height:number;
constructor(w:number, h:number)
{
this.width = w;
this.height = h;
}
area():number
{
return this.width*this.height;
}
}
© 1996-2017 All Rights Reserved.
Describing Array Type
lifemichael
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));
© 1996-2017 All Rights Reserved.
Structural Typing
 TypeScript is a structural type programming
language. It isn't a nominative one.
 We can treat an object as if it is of another type
even if it doesn't officially inherit it. It is a
question of whether the structure match... or
not.
lifemichael
f
© 1996-2017 All Rights Reserved.
Structural Typing
lifemichael
class Person
{
id:number;
name:string;
//details()
//{
//}
}
class Manager
{
id:number;
name:string;
salary:number;
}
var ob:Person = new Manager();
© 1996-2017 All Rights Reserved.
lifemichael
Questions & Answers
If you enjoyed my lecture please leave me a comment
at http://speakerpedia.com/speakers/life-michael.
Thanks for your time!
Haim.

More Related Content

What's hot

Python Basics.pdf
Python Basics.pdfPython Basics.pdf
Python Basics.pdf
FaizanAli561069
 
整数列圧縮
整数列圧縮整数列圧縮
整数列圧縮JAVA DM
 
7 rules of simple and maintainable code
7 rules of simple and maintainable code7 rules of simple and maintainable code
7 rules of simple and maintainable code
Geshan Manandhar
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
Dennis Chang
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
Devashish Kumar
 
IDE Falcon C++
IDE Falcon C++IDE Falcon C++
IDE Falcon C++
Marcos Castro
 
リッチなドメインモデル 名前探し
リッチなドメインモデル 名前探しリッチなドメインモデル 名前探し
リッチなドメインモデル 名前探し
増田 亨
 
Java reflection
Java reflectionJava reflection
Java reflection
NexThoughts Technologies
 
Drupal のコア要素を知る ~構築を支える道具立て~
Drupal のコア要素を知る ~構築を支える道具立て~Drupal のコア要素を知る ~構築を支える道具立て~
Drupal のコア要素を知る ~構築を支える道具立て~
Kenji Shirane
 
Refactoring-ch7 moving feature btw objects
Refactoring-ch7 moving feature btw objectsRefactoring-ch7 moving feature btw objects
Refactoring-ch7 moving feature btw objects
fungfung Chen
 
Java Coleções
Java ColeçõesJava Coleções
Java Coleções
Mario Jorge Pereira
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
LPU
 
Pointers in c
Pointers in cPointers in c
Pointers in cMohd Arif
 
Object oriented programming in java
Object oriented programming in javaObject oriented programming in java
Object oriented programming in java
Elizabeth alexander
 
ドメインロジックに集中せよ 〜ドメイン駆動設計 powered by Spring
ドメインロジックに集中せよ 〜ドメイン駆動設計 powered by Springドメインロジックに集中せよ 〜ドメイン駆動設計 powered by Spring
ドメインロジックに集中せよ 〜ドメイン駆動設計 powered by Spring
増田 亨
 
Curso java 03 - métodos e parâmetros
Curso java   03 - métodos e parâmetrosCurso java   03 - métodos e parâmetros
Curso java 03 - métodos e parâmetrosMaurício Linhares
 
環境構築から始めるDjangoチュートリアル
環境構築から始めるDjangoチュートリアル環境構築から始めるDjangoチュートリアル
環境構築から始めるDjangoチュートリアル
sakihohoribe
 
Java String class
Java String classJava String class
Java String class
DrRajeshreeKhande
 

What's hot (20)

Python Basics.pdf
Python Basics.pdfPython Basics.pdf
Python Basics.pdf
 
整数列圧縮
整数列圧縮整数列圧縮
整数列圧縮
 
7 rules of simple and maintainable code
7 rules of simple and maintainable code7 rules of simple and maintainable code
7 rules of simple and maintainable code
 
C++ Programming Course
C++ Programming CourseC++ Programming Course
C++ Programming Course
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
 
IDE Falcon C++
IDE Falcon C++IDE Falcon C++
IDE Falcon C++
 
リッチなドメインモデル 名前探し
リッチなドメインモデル 名前探しリッチなドメインモデル 名前探し
リッチなドメインモデル 名前探し
 
Java reflection
Java reflectionJava reflection
Java reflection
 
Drupal のコア要素を知る ~構築を支える道具立て~
Drupal のコア要素を知る ~構築を支える道具立て~Drupal のコア要素を知る ~構築を支える道具立て~
Drupal のコア要素を知る ~構築を支える道具立て~
 
Refactoring-ch7 moving feature btw objects
Refactoring-ch7 moving feature btw objectsRefactoring-ch7 moving feature btw objects
Refactoring-ch7 moving feature btw objects
 
Java Coleções
Java ColeçõesJava Coleções
Java Coleções
 
16717 functions in C++
16717 functions in C++16717 functions in C++
16717 functions in C++
 
Pointers in c
Pointers in cPointers in c
Pointers in c
 
Object oriented programming in java
Object oriented programming in javaObject oriented programming in java
Object oriented programming in java
 
ドメインロジックに集中せよ 〜ドメイン駆動設計 powered by Spring
ドメインロジックに集中せよ 〜ドメイン駆動設計 powered by Springドメインロジックに集中せよ 〜ドメイン駆動設計 powered by Spring
ドメインロジックに集中せよ 〜ドメイン駆動設計 powered by Spring
 
POO - 11 - Prática de Herança
POO - 11 - Prática de HerançaPOO - 11 - Prática de Herança
POO - 11 - Prática de Herança
 
Curso java 03 - métodos e parâmetros
Curso java   03 - métodos e parâmetrosCurso java   03 - métodos e parâmetros
Curso java 03 - métodos e parâmetros
 
環境構築から始めるDjangoチュートリアル
環境構築から始めるDjangoチュートリアル環境構築から始めるDjangoチュートリアル
環境構築から始めるDjangoチュートリアル
 
Encapsulamento em oo
Encapsulamento em ooEncapsulamento em oo
Encapsulamento em oo
 
Java String class
Java String classJava String class
Java String class
 

Similar to Advanced topics in TypeScript

Functional programming in Java
Functional programming in Java  Functional programming in Java
Functional programming in Java
Haim Michael
 
Java 8 Streams - in Depth
Java 8 Streams - in DepthJava 8 Streams - in Depth
Java 8 Streams - in Depth
Haim Michael
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
Haim Michael
 
Java 8 Default Methods
Java 8 Default MethodsJava 8 Default Methods
Java 8 Default Methods
Haim Michael
 
Introduction To TensorFlow | Deep Learning Using TensorFlow | TensorFlow Tuto...
Introduction To TensorFlow | Deep Learning Using TensorFlow | TensorFlow Tuto...Introduction To TensorFlow | Deep Learning Using TensorFlow | TensorFlow Tuto...
Introduction To TensorFlow | Deep Learning Using TensorFlow | TensorFlow Tuto...
Edureka!
 
PHP7. Game Changer.
PHP7. Game Changer. PHP7. Game Changer.
PHP7. Game Changer.
Haim Michael
 
MaciasWinter 2020ENG 107Project #2A Year in Gami.docx
MaciasWinter 2020ENG 107Project #2A Year in Gami.docxMaciasWinter 2020ENG 107Project #2A Year in Gami.docx
MaciasWinter 2020ENG 107Project #2A Year in Gami.docx
croysierkathey
 
Rits Brown Bag - TypeScript
Rits Brown Bag - TypeScriptRits Brown Bag - TypeScript
Rits Brown Bag - TypeScript
Right IT Services
 
Build a Game With JavaScript (May 2017, DTLA)
Build a Game With JavaScript (May 2017, DTLA)Build a Game With JavaScript (May 2017, DTLA)
Build a Game With JavaScript (May 2017, DTLA)
Thinkful
 
Bring Your Own Apache MXNet and TensorFlow Scripts to Amazon SageMaker (AIM35...
Bring Your Own Apache MXNet and TensorFlow Scripts to Amazon SageMaker (AIM35...Bring Your Own Apache MXNet and TensorFlow Scripts to Amazon SageMaker (AIM35...
Bring Your Own Apache MXNet and TensorFlow Scripts to Amazon SageMaker (AIM35...
Amazon Web Services
 
Build Deep Learning Applications Using Apache MXNet, Featuring Workday (AIM40...
Build Deep Learning Applications Using Apache MXNet, Featuring Workday (AIM40...Build Deep Learning Applications Using Apache MXNet, Featuring Workday (AIM40...
Build Deep Learning Applications Using Apache MXNet, Featuring Workday (AIM40...
Amazon Web Services
 
Intro to JavaScript - Thinkful LA
Intro to JavaScript - Thinkful LAIntro to JavaScript - Thinkful LA
Intro to JavaScript - Thinkful LA
Thinkful
 
OOP Best Practices in JavaScript
OOP Best Practices in JavaScriptOOP Best Practices in JavaScript
OOP Best Practices in JavaScript
Haim Michael
 
Build Deep Learning Applications Using Apache MXNet - Featuring Chick-fil-A (...
Build Deep Learning Applications Using Apache MXNet - Featuring Chick-fil-A (...Build Deep Learning Applications Using Apache MXNet - Featuring Chick-fil-A (...
Build Deep Learning Applications Using Apache MXNet - Featuring Chick-fil-A (...
Amazon Web Services
 
PHP 5.4 New Features
PHP 5.4 New FeaturesPHP 5.4 New Features
PHP 5.4 New Features
Haim Michael
 
Open mp
Open mpOpen mp
Open mp
Gopi Saiteja
 
Kotlin Crash Course
Kotlin Crash CourseKotlin Crash Course
Kotlin Crash Course
Haim Michael
 
[GRCPP] Introduction to concepts (C++20)
[GRCPP] Introduction to concepts (C++20)[GRCPP] Introduction to concepts (C++20)
[GRCPP] Introduction to concepts (C++20)
Dimitrios Platis
 
Intro to programing with java-lecture 3
Intro to programing with java-lecture 3Intro to programing with java-lecture 3
Intro to programing with java-lecture 3
Mohamed Essam
 
the refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxthe refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptx
AnkitaVerma776806
 

Similar to Advanced topics in TypeScript (20)

Functional programming in Java
Functional programming in Java  Functional programming in Java
Functional programming in Java
 
Java 8 Streams - in Depth
Java 8 Streams - in DepthJava 8 Streams - in Depth
Java 8 Streams - in Depth
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
 
Java 8 Default Methods
Java 8 Default MethodsJava 8 Default Methods
Java 8 Default Methods
 
Introduction To TensorFlow | Deep Learning Using TensorFlow | TensorFlow Tuto...
Introduction To TensorFlow | Deep Learning Using TensorFlow | TensorFlow Tuto...Introduction To TensorFlow | Deep Learning Using TensorFlow | TensorFlow Tuto...
Introduction To TensorFlow | Deep Learning Using TensorFlow | TensorFlow Tuto...
 
PHP7. Game Changer.
PHP7. Game Changer. PHP7. Game Changer.
PHP7. Game Changer.
 
MaciasWinter 2020ENG 107Project #2A Year in Gami.docx
MaciasWinter 2020ENG 107Project #2A Year in Gami.docxMaciasWinter 2020ENG 107Project #2A Year in Gami.docx
MaciasWinter 2020ENG 107Project #2A Year in Gami.docx
 
Rits Brown Bag - TypeScript
Rits Brown Bag - TypeScriptRits Brown Bag - TypeScript
Rits Brown Bag - TypeScript
 
Build a Game With JavaScript (May 2017, DTLA)
Build a Game With JavaScript (May 2017, DTLA)Build a Game With JavaScript (May 2017, DTLA)
Build a Game With JavaScript (May 2017, DTLA)
 
Bring Your Own Apache MXNet and TensorFlow Scripts to Amazon SageMaker (AIM35...
Bring Your Own Apache MXNet and TensorFlow Scripts to Amazon SageMaker (AIM35...Bring Your Own Apache MXNet and TensorFlow Scripts to Amazon SageMaker (AIM35...
Bring Your Own Apache MXNet and TensorFlow Scripts to Amazon SageMaker (AIM35...
 
Build Deep Learning Applications Using Apache MXNet, Featuring Workday (AIM40...
Build Deep Learning Applications Using Apache MXNet, Featuring Workday (AIM40...Build Deep Learning Applications Using Apache MXNet, Featuring Workday (AIM40...
Build Deep Learning Applications Using Apache MXNet, Featuring Workday (AIM40...
 
Intro to JavaScript - Thinkful LA
Intro to JavaScript - Thinkful LAIntro to JavaScript - Thinkful LA
Intro to JavaScript - Thinkful LA
 
OOP Best Practices in JavaScript
OOP Best Practices in JavaScriptOOP Best Practices in JavaScript
OOP Best Practices in JavaScript
 
Build Deep Learning Applications Using Apache MXNet - Featuring Chick-fil-A (...
Build Deep Learning Applications Using Apache MXNet - Featuring Chick-fil-A (...Build Deep Learning Applications Using Apache MXNet - Featuring Chick-fil-A (...
Build Deep Learning Applications Using Apache MXNet - Featuring Chick-fil-A (...
 
PHP 5.4 New Features
PHP 5.4 New FeaturesPHP 5.4 New Features
PHP 5.4 New Features
 
Open mp
Open mpOpen mp
Open mp
 
Kotlin Crash Course
Kotlin Crash CourseKotlin Crash Course
Kotlin Crash Course
 
[GRCPP] Introduction to concepts (C++20)
[GRCPP] Introduction to concepts (C++20)[GRCPP] Introduction to concepts (C++20)
[GRCPP] Introduction to concepts (C++20)
 
Intro to programing with java-lecture 3
Intro to programing with java-lecture 3Intro to programing with java-lecture 3
Intro to programing with java-lecture 3
 
the refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptxthe refernce of programming C notes ppt.pptx
the refernce of programming C notes ppt.pptx
 

More from Haim Michael

Kotlin Jump Start Online Free Meetup (June 4th, 2024)
Kotlin Jump Start Online Free Meetup (June 4th, 2024)Kotlin Jump Start Online Free Meetup (June 4th, 2024)
Kotlin Jump Start Online Free Meetup (June 4th, 2024)
Haim Michael
 
Anti Patterns
Anti PatternsAnti Patterns
Anti Patterns
Haim Michael
 
Virtual Threads in Java
Virtual Threads in JavaVirtual Threads in Java
Virtual Threads in Java
Haim Michael
 
MongoDB Design Patterns
MongoDB Design PatternsMongoDB Design Patterns
MongoDB Design Patterns
Haim Michael
 
Introduction to SQL Injections
Introduction to SQL InjectionsIntroduction to SQL Injections
Introduction to SQL Injections
Haim Michael
 
Record Classes in Java
Record Classes in JavaRecord Classes in Java
Record Classes in Java
Haim Michael
 
Microservices Design Patterns
Microservices Design PatternsMicroservices Design Patterns
Microservices Design Patterns
Haim Michael
 
Structural Pattern Matching in Python
Structural Pattern Matching in PythonStructural Pattern Matching in Python
Structural Pattern Matching in Python
Haim Michael
 
Unit Testing in Python
Unit Testing in PythonUnit Testing in Python
Unit Testing in Python
Haim Michael
 
Java Jump Start
Java Jump StartJava Jump Start
Java Jump Start
Haim Michael
 
JavaScript Jump Start 20220214
JavaScript Jump Start 20220214JavaScript Jump Start 20220214
JavaScript Jump Start 20220214
Haim Michael
 
Bootstrap Jump Start
Bootstrap Jump StartBootstrap Jump Start
Bootstrap Jump Start
Haim Michael
 
What is new in PHP
What is new in PHPWhat is new in PHP
What is new in PHP
Haim 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.9
Haim Michael
 
Programming in Python on Steroid
Programming in Python on SteroidProgramming in Python on Steroid
Programming in Python on Steroid
Haim Michael
 
The matplotlib Library
The matplotlib LibraryThe matplotlib Library
The matplotlib Library
Haim Michael
 
Pandas meetup 20200908
Pandas meetup 20200908Pandas meetup 20200908
Pandas meetup 20200908
Haim Michael
 
The num py_library_20200818
The num py_library_20200818The num py_library_20200818
The num py_library_20200818
Haim Michael
 
Jupyter notebook 20200728
Jupyter notebook 20200728Jupyter notebook 20200728
Jupyter notebook 20200728
Haim 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
 

More from Haim Michael (20)

Kotlin Jump Start Online Free Meetup (June 4th, 2024)
Kotlin Jump Start Online Free Meetup (June 4th, 2024)Kotlin Jump Start Online Free Meetup (June 4th, 2024)
Kotlin Jump Start Online Free Meetup (June 4th, 2024)
 
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
 
Unit Testing in Python
Unit Testing in PythonUnit Testing in Python
Unit Testing 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
 
Programming in Python on Steroid
Programming in Python on SteroidProgramming in Python on Steroid
Programming in Python on Steroid
 
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)
 

Recently uploaded

7 Best Cloud Hosting Services to Try Out in 2024
7 Best Cloud Hosting Services to Try Out in 20247 Best Cloud Hosting Services to Try Out in 2024
7 Best Cloud Hosting Services to Try Out in 2024
Danica Gill
 
Understanding User Behavior with Google Analytics.pdf
Understanding User Behavior with Google Analytics.pdfUnderstanding User Behavior with Google Analytics.pdf
Understanding User Behavior with Google Analytics.pdf
SEO Article Boost
 
2.Cellular Networks_The final stage of connectivity is achieved by segmenting...
2.Cellular Networks_The final stage of connectivity is achieved by segmenting...2.Cellular Networks_The final stage of connectivity is achieved by segmenting...
2.Cellular Networks_The final stage of connectivity is achieved by segmenting...
JeyaPerumal1
 
Bài tập unit 1 English in the world.docx
Bài tập unit 1 English in the world.docxBài tập unit 1 English in the world.docx
Bài tập unit 1 English in the world.docx
nhiyenphan2005
 
Gen Z and the marketplaces - let's translate their needs
Gen Z and the marketplaces - let's translate their needsGen Z and the marketplaces - let's translate their needs
Gen Z and the marketplaces - let's translate their needs
Laura Szabó
 
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
3ipehhoa
 
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdfJAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
Javier Lasa
 
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
zyfovom
 
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
ufdana
 
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Brad Spiegel Macon GA
 
[HUN][hackersuli] Red Teaming alapok 2024
[HUN][hackersuli] Red Teaming alapok 2024[HUN][hackersuli] Red Teaming alapok 2024
[HUN][hackersuli] Red Teaming alapok 2024
hackersuli
 
test test test test testtest test testtest test testtest test testtest test ...
test test  test test testtest test testtest test testtest test testtest test ...test test  test test testtest test testtest test testtest test testtest test ...
test test test test testtest test testtest test testtest test testtest test ...
Arif0071
 
guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...
Rogerio Filho
 
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
eutxy
 
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
keoku
 
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
3ipehhoa
 
Explore-Insanony: Watch Instagram Stories Secretly
Explore-Insanony: Watch Instagram Stories SecretlyExplore-Insanony: Watch Instagram Stories Secretly
Explore-Insanony: Watch Instagram Stories Secretly
Trending Blogers
 
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
3ipehhoa
 
Search Result Showing My Post is Now Buried
Search Result Showing My Post is Now BuriedSearch Result Showing My Post is Now Buried
Search Result Showing My Post is Now Buried
Trish Parr
 
1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...
JeyaPerumal1
 

Recently uploaded (20)

7 Best Cloud Hosting Services to Try Out in 2024
7 Best Cloud Hosting Services to Try Out in 20247 Best Cloud Hosting Services to Try Out in 2024
7 Best Cloud Hosting Services to Try Out in 2024
 
Understanding User Behavior with Google Analytics.pdf
Understanding User Behavior with Google Analytics.pdfUnderstanding User Behavior with Google Analytics.pdf
Understanding User Behavior with Google Analytics.pdf
 
2.Cellular Networks_The final stage of connectivity is achieved by segmenting...
2.Cellular Networks_The final stage of connectivity is achieved by segmenting...2.Cellular Networks_The final stage of connectivity is achieved by segmenting...
2.Cellular Networks_The final stage of connectivity is achieved by segmenting...
 
Bài tập unit 1 English in the world.docx
Bài tập unit 1 English in the world.docxBài tập unit 1 English in the world.docx
Bài tập unit 1 English in the world.docx
 
Gen Z and the marketplaces - let's translate their needs
Gen Z and the marketplaces - let's translate their needsGen Z and the marketplaces - let's translate their needs
Gen Z and the marketplaces - let's translate their needs
 
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
 
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdfJAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
 
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
学位认证网(DU毕业证)迪肯大学毕业证成绩单一比一原版制作
 
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
 
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
 
[HUN][hackersuli] Red Teaming alapok 2024
[HUN][hackersuli] Red Teaming alapok 2024[HUN][hackersuli] Red Teaming alapok 2024
[HUN][hackersuli] Red Teaming alapok 2024
 
test test test test testtest test testtest test testtest test testtest test ...
test test  test test testtest test testtest test testtest test testtest test ...test test  test test testtest test testtest test testtest test testtest test ...
test test test test testtest test testtest test testtest test testtest test ...
 
guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...
 
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
 
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
一比一原版(SLU毕业证)圣路易斯大学毕业证成绩单专业办理
 
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
原版仿制(uob毕业证书)英国伯明翰大学毕业证本科学历证书原版一模一样
 
Explore-Insanony: Watch Instagram Stories Secretly
Explore-Insanony: Watch Instagram Stories SecretlyExplore-Insanony: Watch Instagram Stories Secretly
Explore-Insanony: Watch Instagram Stories Secretly
 
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
 
Search Result Showing My Post is Now Buried
Search Result Showing My Post is Now BuriedSearch Result Showing My Post is Now Buried
Search Result Showing My Post is Now Buried
 
1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...1.Wireless Communication System_Wireless communication is a broad term that i...
1.Wireless Communication System_Wireless communication is a broad term that i...
 

Advanced topics in TypeScript

  • 1. © 1996-2017 All Rights Reserved. Advanced Topics in TypeScript Haim Michael October 17st , 2017 All logos, trade marks and brand names used in this presentation belong to the respective owners. lifemichael You can watch the video at https://youtu.be/lIbConUCkRs TypeScript
  • 2. © 1996-2017 All Rights Reserved. Haim Michael Introduction ● Snowboarding. Learning. Coding. Teaching. More than 16 years of Practical Experience. lifemichael
  • 3. © 1996-2017 All Rights Reserved. Haim 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
  • 4. © 1996-2017 All Rights Reserved. Introduction  “TypeScript is a typed superset of JavaScript that compiles to plain JavaScript.” www.typescriptlang.org lifemichael
  • 5. © 1996-2017 All Rights Reserved. Fast Evolvement  TypeScript evolves probably faster than any other programming language. 12/10/2017 – 2.6rc 31/8/2017 – 2.5 27/6/2017 – 2.4 27/4/2017 – 2.3 22/2/2017 – 2.2 ... lifemichael
  • 6. © 1996-2017 All Rights Reserved. The // @ts-ignore Comment  Using this comment (available as of 2.6) we can suppress error messages. lifemichael if (false) { //@ts-ignore console.log("hello"); }
  • 7. © 1996-2017 All Rights Reserved. Localized Diagnostic Messages  As of 2.6, we can add the --locale flag for getting localized messages. lifemichael if (false) { console.log("hello"); }
  • 8. © 1996-2017 All Rights Reserved. Optional catch clause Variable  As of 2.5, we can avoid specifying a variable in the catch clause. lifemichael let input = "..."; try { JSON.parse(input); } catch { console.log("invalid json:nn" + input) }
  • 9. © 1996-2017 All Rights Reserved. Anonymous Class Type  As of 1.6 we can define a class without specifying its name. We can write a class expression, which is a class definition without specifying its name.  It is very similar to the possibility to define anonymous function. lifemichael
  • 10. © 1996-2017 All Rights Reserved. Anonymous Class Type lifemichael let Point = class { Constructor( public x: number, public y: number) { } public length() { return Math.sqrt( this.x * this.x + this.y * this.y); } }; var p = new Point(3, 4); console.log(p.length());
  • 11. © 1996-2017 All Rights Reserved. Type Alias  As of 1.4 we can define custom alias for types that were already defined. lifemichael type Calc = ((a:number,b:number)=>number) var f1:Calc = function(num1,num2){ return num1+num2; } var f2:Calc = function(num1,num2){ return num1*num2; } var temp = f1(45,5) console.log(temp)
  • 12. © 1996-2017 All Rights Reserved. Type Alias  As of 1.6 the type alias can be generic. lifemichael type Create<T> = (() => T); var f3:Create<number> = function(){ return 12; }; var f4:Create<string> = function(){ return "abc"; } console.log(f4());
  • 13. © 1996-2017 All Rights Reserved. Union Types  As of 1.4 we can combine multiple types into one. lifemichael let destination:string|string[]; destination = "tel-aviv"; destination = ["tel-aviv","haifa","jerusalem"]
  • 14. © 1996-2017 All Rights Reserved. Union Types lifemichael interface IBook { id: string; pages: number; } interface INewspaper { companyId: string; } type IPublication = IBook | INewspaper; let ob: IPublication = { id: 'ID3241', pages: 21 };
  • 15. © 1996-2017 All Rights Reserved. Union Types  We can use the same syntax for specifying that the returned value of a specific function is either of the first type or the second (or the third.. etc). Doing so is known as types guarding. lifemichael
  • 16. © 1996-2017 All Rights Reserved. Union Types lifemichael class Student{} class Teacher{} function getResponsible(n: number): Student | Teacher { if (n === 1) { return new Teacher(); } else { return new Student(); } }
  • 17. © 1996-2017 All Rights Reserved. Accessors  TypeScript allows us to define accessors, also known as properties, in our code. lifemichael
  • 18. © 1996-2017 All Rights Reserved. Accessors lifemichael class Rectangle { private _width:number; private _height:number; constructor(width: number, height: number) { this._width = width; this._height = height; } get width(): number { return this._width; } set width(value: number) { if(value>0) { this._width = value; } }
  • 19. © 1996-2017 All Rights Reserved. get height(): number { return this._height; } set height(value: number) { this._height = value; } public area():number { return this.height*this.width; } } var rec:Rectangle = new Rectangle(4,5); rec.width = 3; document.write("area is "+rec.area()); Accessors lifemichael
  • 20. © 1996-2017 All Rights Reserved. Optional Parameters  Unlike JavaScript, when calling a function passing over arguments the number of arguments must match the number of the parameters. If the number of arguments doesn't match the number of parameters then we shall get a compilation error. lifemichael
  • 21. © 1996-2017 All Rights Reserved. Optional Parameters  Adding the question mark to the name of a parameter will turn that parameter into an optional one.  The parameters that are not optional are also known as the required parameters. The required parameters cannot come after the optional ones. lifemichael
  • 22. © 1996-2017 All Rights Reserved. Optional Parameters  The optional parameters should be after any other required one. They should be the last ones. lifemichael
  • 23. © 1996-2017 All Rights Reserved. Optional Parameters lifemichael function sum(a,b,c?) { var total = 0; if(c!==undefined) { total += c; } total += (a+b); return total; } var temp = sum(7,8); document.write("temp="+temp);
  • 24. © 1996-2017 All Rights Reserved. Default Parameters  When defining a function we can specify default values for any of its parameters. Doing so, if an argument is not passed over to the parameter then the default value we specified will be set instead.  The default value we assign a parameter can be the value of expression evaluated during runtime. lifemichael
  • 25. © 1996-2017 All Rights Reserved. Default Parameters lifemichael function dosomething(a,b,step=((b-a)%5)) { var i=a; while(a<=b) { document.write("<br/>"+a); a+=step; } } dosomething(1,20);
  • 26. © 1996-2017 All Rights Reserved. Rest Parameters  The rest parameter is a parameter that when we call the function we pass over zero or more arguments of the specified type to it.  Each function can include one rest parameter at the most. We cannot have more than that.  The type of the rest parameter must be the array type. lifemichael
  • 27. © 1996-2017 All Rights Reserved. Rest Parameters  In order to define a rest parameter we just need to prefix the parameter with three periods. lifemichael function sum(...numbers: number[]):number { var total:number = 0; for(var i=0; i<numbers.length; i++) { total += numbers[i]; } return total; } document.write("<br/>"+sum(2,5,3));
  • 28. © 1996-2017 All Rights Reserved. Generics Constraint  When using the parameter type we can specify constraints in order to limit the range of possible types. lifemichael 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; }
  • 29. © 1996-2017 All Rights Reserved. Generics Constraint lifemichael 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; } }
  • 30. © 1996-2017 All Rights Reserved. Describing Function Type  We can use an interface for describing a function type. lifemichael interface CalculateFunction { (a:number,b:number):number; }
  • 31. © 1996-2017 All Rights Reserved. Describing Function Type lifemichael 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));
  • 32. © 1996-2017 All Rights Reserved. Describing Array Type  We can use an interface for describing an array type. lifemichael interface RectanglesArray { [index: number]: Rectangle; length:number; }
  • 33. © 1996-2017 All Rights Reserved. Describing Array Type lifemichael class Rectangle { width:number; height:number; constructor(w:number, h:number) { this.width = w; this.height = h; } area():number { return this.width*this.height; } }
  • 34. © 1996-2017 All Rights Reserved. Describing Array Type lifemichael 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));
  • 35. © 1996-2017 All Rights Reserved. Structural Typing  TypeScript is a structural type programming language. It isn't a nominative one.  We can treat an object as if it is of another type even if it doesn't officially inherit it. It is a question of whether the structure match... or not. lifemichael f
  • 36. © 1996-2017 All Rights Reserved. Structural Typing lifemichael class Person { id:number; name:string; //details() //{ //} } class Manager { id:number; name:string; salary:number; } var ob:Person = new Manager();
  • 37. © 1996-2017 All Rights Reserved. lifemichael Questions & Answers If you enjoyed my lecture please leave me a comment at http://speakerpedia.com/speakers/life-michael. Thanks for your time! Haim.