SlideShare ist ein Scribd-Unternehmen logo
1 von 36
Working with TypeScript
Oswald Campesato
Consultant/Training:
www.iquarkt.com
ocampesato@yahoo.com
What is TypeScript?
• Microsoft created TypeScript in October/2012
• Supports ES6
• Supports interfaces and sub-interfaces
• Supports classes and subclasses
• Optional type system
• Angular 2 is written in Typescript
https://scotch.io/tutorials/why-you-shouldnt-be-scared-of-
typescript8
More TypeScript Details
• A compiled language (tsc compiler)
• strong typing and also type inferencing
• type checking during compile time
• "minimal" extra compile time overhead
• tsc transpiles ".ts" files into ".js" files
• [sudo] npm install –g typescript // <- installs “tsc”
Links with TypeScript Details
• Official TypeScript website:
http://www.typescriptlang.org/
• Typings: TypeScript Definition Manager:
https://github.com/typings/typings
Definitely Typed: 3rd-party TypeScript Definitions:
http://definitelytyped.org/
Browser Support for TypeScript
• Browsers support only ECMA5
• TypeScript is transpiled to ECMA5
• ES6 is transpiled to ECMA5
• TypeScript playground:
https://www.typescriptlang.org/play/
• tsc is the TypeScript compiler (can also use Babel)
TypeScript Exposes 9 Types
• Boolean
• Number
• String
• Array
• Tuple
• Enum
• Any
• Void
• Function
Additions to TypeScript
• Types
• Classes
• Annotations
• Imports
• language utilities (e.g. destructuring)
• interfaces
• inheritance
• generics
Simple Types in TypeScript
• var isDone: boolean = false;
• var height: number = 6;
• var name: string = "dave";
• var myList:number[] = [1, 2, 3]; // option #1
• var myList:Array<number> = [1, 2, 3]; // option #2
• var changeMe: any = 4;
• changeMe = ”I’m a string now";
• var myList:any[] = [1, true, ”pizza"];
ECMA5 vs TypeScript Functions
• ECMA5 version:
• function add(a,b) { return a+b; }
• add(1,4); // 5
• add(1,’4'); // 14 (valid in ECMA5)
• TypeScript version:
• function add(a:number, b:number) { return a+b; }
• add(1,4); // 5
• add(1,’4'); // (error in TypeScript)
Functions in TypeScript
• msg is an argument of type string and return type is
void in the myLogger function:
• function myLogger(msg?:string): void {
• console.log("My custom logger: “+msg);
• }
• Note: the trailing question mark (“?”) after msg
indicates that msg is an optional argument
Simple Iteration: Factorial
• factorial(n) {
• var prod = 1;
• for(var i=1; i<=n; n++) {
• prod *= i;
• console.log(“factorial “+i+” = “+prod);
• }
• return prod;
• }
• console.log(“factorial 5 = “+factorial(5));
• console.log(“factorial 10 = “+factorial(10));
Exercises: Iteration
• 1) EvenP: calculate the product of the even integers
between 1 and n
• 2) Prime: check if the positive integer n is prime (its
only divisors are 1 and itself)
• 3) print the primes between 2 and 100
• 4) Goldbach’s conjecture: every even number greater
than 2 can be written as a sum of two odd primes:
write a function to show it’s true up to 100 (use #3)
• 5) use #4 to find even numbers with multiple
solutions, such as 14 (=3+11 = 7+7)
Simple Recursion: Factorial
• factorial(n) {
• if(n <= 1) return 1;
• else return n * factorial(n-1)
• }
• console.log(“factorial 5 = “+factorial(5));
• console.log(“factorial 10 = “+factorial(10));
Tail Recursion: Factorial
• factorial(n, prod) {
• if(n <= 1) return prod;
• else return factorial(n-1, n*prod)
• }
• console.log(“factorial 5 = “+factorial(5,1));
• console.log(“factorial 10 = “+factorial(10,1));
Exercises: Recursion
1) use Euclid’s algorithm to find the GCD of two positive
integers (GCD = Greatest Common Divisor)
Example: GCD(10,24) = 2
2) use #1 to find the LCM of two positive integers
(where LCM = Lowest Common Multiple)
Note: LCM(a,b) = a*b/gcd(a,b)
Example: LCM(10,24) = 120
3) Use recursion to calculate Fibonacci(20)
Generics in TypeScript
• Similar to a generic in other languages:
• function identity<T>(arg: T): T {
• return arg;
• }
•
• // output has 'string' type (explicit/inferred):
• var output = identity<string>("Dave");
• var output = identity("Dave");
tsc: Transpiles TypeScript to ECMA5
• 1) version number:
tsc –version
• 2) compile the TS file app.ts:
tsc app.ts (will generate app.js)
• 3) watch for files changes in app.ts:
a) tsc –-watch app.ts
b) tsc –-watch –out bundle.js app.ts
4) tsc –help lists the available options
Output from tsc --init
• {
• "compilerOptions": {
• "module": "commonjs",
• "target": "es3",
• "noImplicitAny": false,
• "outDir": "built",
• "rootDir": ".",
• "sourceMap": false
• },
• "exclude": [
• "node_modules"
• ]
• } // ‘tsc‘ will now compile all TS files in directory
Sample tsconfig.json for Angular 2
• {
• "version": "1.7.5",
• "compilerOptions": {
• "emitDecoratorMetadata": true,
• "experimentalDecorators": true,
• "target": "es5",
• "module": "system",
• "moduleResolution": "node",
• "removeComments": true,
• "sourceMap": true,
• "outDir": "dist"
• },
• "exclude": [
• "node_modules"
• ]
• }
Compilation with tsc
• 1) create the following class in app.ts:
class MyClass { }
• 2) compile the previous class:
tsc app.ts
• 3) step #2 generates this code in app.js:
var MyClass = (function () {
function MyClass() {
}
return MyClass;
})();
Interfaces in TypeScript (1)
interface IUser {
fname: string;
lname: string;
weight?: number; // optional
}
function displayUser(user: IUser) {
console.log("First name = "+user.fname);
}
Interfaces in TypeScript (2)
interface IUser {
fname: string;
lname: string;
weight?: number; // optional
}
// the following code works correctly:
var aUser =
{fname: "John", lname: "Smith", weight:200};
displayUser(aUser);
ES6 Class versus TypeScript Class
class ES6Class { // ES6 Class
constructor(items) { // no type definition
this.items = items;
}
}
let mye6s = new ES6Class([1,2,3]);
console.log(myes6s.items);
class TSClass { // TypeScript Class
items: string[];
constructor(items: string[]) { this.items = items; }
}
let myts = new TSClass([1,2,3]);
console.log(myts.items);
Classes in TypeScript (1)
class User {
fname: string;
lname: string;
weight: number;
constructor(fname:string, lname:string, weight:number) {
this.fname = fname;
this.lname = lname;
this.weight = weight;
}
fullname():string {
return (this.fname+" "+this.lname+" weighs "+this.weight);
}
}
Classes in TypeScript (2)
var u1:User, u2:User;
u1 = new User("Jane", "Smith");
u2 = new User("John", "Jones");
console.log("user1 = "+u1.fullname());
console.log("user2 = "+u2.fullname());
JSON to a TypeScript Class (1)
var people = [
{fname:"Jane",lname:"Smith",zip:"94043"},
{fname:"John",lname:"Jones",zip:"94539"},
{fname:"Dave",lname:"Starr",zip:"67800"}
]
JSON to a TypeScript Class (2)
class Person {
//unnecessary because constructor specifies “public”:
//fname:string;
//lname:string;
//zip:string;
constructor(public fname:string,
public lname:string,
public zip:string) {
this.fname = fname;
this.lname = lname;
this.zip = zip;
}
}
JSON to a TypeScript Class (3)
var TSPeople = [
new Person("Jane","Smith","94043"),
new Person("John","Jones","94539"),
new Person("Dave","Starr","67800")
];
Implementing TypeScript Interfaces (1)
Interface IRect = {
width: number;
height: number;
perimeter: number;
area: number;
}
Implementing TypeScript Interfaces (2)
class Rectangle implements IRect {
constructor(public width:number,
public height:number) {
this.width = width;
this.height = height;
}
public getArea() { return width*height }
public getPerimeter() { return 2*(width+height) }
}
Implementing TypeScript Interfaces (3)
var rect1 = new Rectangle(5,10);
console.log(“area = “+rect1.getArea());
console.log(“perimeter = “+rect1.getPerimeter());
var rect2 = new Rectangle(12,20);
console.log(“area = “+rect2.getArea());
console.log(“perimeter = “+rect2.getPerimeter());
TypeScript Subclasses
class Square extends Rectangle {
constructor(public side:number, width:number, height:number) {
super(width, height);
this.side = side;
}
area(): void {}
perimeter(): void {}
}
var square1 = new Square(20);
console.log("area = "+square1.getArea());
console.log("perimeter = "+square1.getPerimeter());
Exercises for Interfaces/Classes
1) Define an interface IPerson that contains a first
name, last name, and zip code
2) Create a Person2 class that implements IPerson:
class Person2 implements IPerson { … }
3) Modify IPerson so that it contains an optional
weight property
IDEs for TypeScript
WebStorm IDE (30-day trial)
Visual Studio Code (free and cross-platform)
TypEcs (TypeScript IDE for Eclipse):
http://typecsdev.com/
http://definitelytyped.org/directory/tools.html
TypeScript Versions
• https://github.com/Microsoft/TypeScript/wiki/Ro
admap
• Navigate to website to see list of features for:
• TS 2.1
• TS 2.0
• TS 1.9
• TS 1.8
• TS 1.7
• TS 1.6
Recent/Upcoming Books and Training
1) HTML5 Canvas and CSS3 Graphics (2013)
2) jQuery, CSS3, and HTML5 for Mobile (2013)
3) HTML5 Pocket Primer (2013)
4) jQuery Pocket Primer (2013)
5) HTML5 Mobile Pocket Primer (2014)
6) D3 Pocket Primer (2015)
7) Python Pocket Primer (2015)
8) SVG Pocket Primer (2016)
9) CSS3 Pocket Primer (2016)
10) Angular 2 Pocket Primer (2016)

Weitere ähnliche Inhalte

Was ist angesagt?

Getting started with typescript and angular 2
Getting started with typescript  and angular 2Getting started with typescript  and angular 2
Getting started with typescript and angular 2Knoldus Inc.
 
TypeScript Modules
TypeScript ModulesTypeScript Modules
TypeScript ModulesNoam Kfir
 
TypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersTypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersRutenis Turcinas
 
Getting Started with TypeScript
Getting Started with TypeScriptGetting Started with TypeScript
Getting Started with TypeScriptGil Fink
 
Typescript Fundamentals
Typescript FundamentalsTypescript Fundamentals
Typescript FundamentalsSunny Sharma
 
TypeScript introduction to scalable javascript application
TypeScript introduction to scalable javascript applicationTypeScript introduction to scalable javascript application
TypeScript introduction to scalable javascript applicationAndrea Paciolla
 
Typescript: enjoying large scale browser development
Typescript: enjoying large scale browser developmentTypescript: enjoying large scale browser development
Typescript: enjoying large scale browser developmentJoost de Vries
 
TypeScript for Java Developers
TypeScript for Java DevelopersTypeScript for Java Developers
TypeScript for Java DevelopersYakov Fain
 
Introducing type script
Introducing type scriptIntroducing type script
Introducing type scriptRemo Jansen
 
Typescript tips & tricks
Typescript tips & tricksTypescript tips & tricks
Typescript tips & tricksOri Calvo
 
Typescript 101 introduction
Typescript 101   introductionTypescript 101   introduction
Typescript 101 introductionBob German
 
Introduction to TypeScript by Winston Levi
Introduction to TypeScript by Winston LeviIntroduction to TypeScript by Winston Levi
Introduction to TypeScript by Winston LeviWinston Levi
 
Typescript in 30mins
Typescript in 30mins Typescript in 30mins
Typescript in 30mins Udaya Kumar
 

Was ist angesagt? (20)

TypeScript
TypeScriptTypeScript
TypeScript
 
Getting started with typescript and angular 2
Getting started with typescript  and angular 2Getting started with typescript  and angular 2
Getting started with typescript and angular 2
 
TypeScript Modules
TypeScript ModulesTypeScript Modules
TypeScript Modules
 
TypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack DevelopersTypeScript - Silver Bullet for the Full-stack Developers
TypeScript - Silver Bullet for the Full-stack Developers
 
Getting Started with TypeScript
Getting Started with TypeScriptGetting Started with TypeScript
Getting Started with TypeScript
 
TypeScript 101
TypeScript 101TypeScript 101
TypeScript 101
 
TypeScript 2 in action
TypeScript 2 in actionTypeScript 2 in action
TypeScript 2 in action
 
TypeScript intro
TypeScript introTypeScript intro
TypeScript intro
 
Typescript Fundamentals
Typescript FundamentalsTypescript Fundamentals
Typescript Fundamentals
 
TypeScript introduction to scalable javascript application
TypeScript introduction to scalable javascript applicationTypeScript introduction to scalable javascript application
TypeScript introduction to scalable javascript application
 
Typescript: enjoying large scale browser development
Typescript: enjoying large scale browser developmentTypescript: enjoying large scale browser development
Typescript: enjoying large scale browser development
 
TypeScript for Java Developers
TypeScript for Java DevelopersTypeScript for Java Developers
TypeScript for Java Developers
 
Introducing TypeScript
Introducing TypeScriptIntroducing TypeScript
Introducing TypeScript
 
Introducing type script
Introducing type scriptIntroducing type script
Introducing type script
 
Typescript tips & tricks
Typescript tips & tricksTypescript tips & tricks
Typescript tips & tricks
 
Typescript 101 introduction
Typescript 101   introductionTypescript 101   introduction
Typescript 101 introduction
 
Introduction to TypeScript by Winston Levi
Introduction to TypeScript by Winston LeviIntroduction to TypeScript by Winston Levi
Introduction to TypeScript by Winston Levi
 
Typescript in 30mins
Typescript in 30mins Typescript in 30mins
Typescript in 30mins
 
Typescript ppt
Typescript pptTypescript ppt
Typescript ppt
 
Learning typescript
Learning typescriptLearning typescript
Learning typescript
 

Ähnlich wie Working with TypeScript - A Concise Guide

A Replay Approach to Software Validation
A Replay Approach to Software ValidationA Replay Approach to Software Validation
A Replay Approach to Software ValidationJames Pascoe
 
Hands on Session on Python
Hands on Session on PythonHands on Session on Python
Hands on Session on PythonSumit Raj
 
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみたスマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみたTaro Matsuzawa
 
Python for Security Professionals
Python for Security ProfessionalsPython for Security Professionals
Python for Security ProfessionalsAditya Shankar
 
A la découverte de TypeScript
A la découverte de TypeScriptA la découverte de TypeScript
A la découverte de TypeScriptDenis Voituron
 
Lex tool manual
Lex tool manualLex tool manual
Lex tool manualSami Said
 
JSLounge - TypeScript 소개
JSLounge - TypeScript 소개JSLounge - TypeScript 소개
JSLounge - TypeScript 소개Reagan Hwang
 
Monitoring and Debugging your Live Applications
Monitoring and Debugging your Live ApplicationsMonitoring and Debugging your Live Applications
Monitoring and Debugging your Live ApplicationsRobert Coup
 
CoderDojo: Intermediate Python programming course
CoderDojo: Intermediate Python programming courseCoderDojo: Intermediate Python programming course
CoderDojo: Intermediate Python programming courseAlexander Galkin
 
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...Cyber Security Alliance
 
シェル芸でライフハック(特論)
シェル芸でライフハック(特論)シェル芸でライフハック(特論)
シェル芸でライフハック(特論)Yuki Shimazaki
 
Webinar alain-2009-03-04-clamav
Webinar alain-2009-03-04-clamavWebinar alain-2009-03-04-clamav
Webinar alain-2009-03-04-clamavthc2cat
 
The Ring programming language version 1.5.2 book - Part 14 of 181
The Ring programming language version 1.5.2 book - Part 14 of 181The Ring programming language version 1.5.2 book - Part 14 of 181
The Ring programming language version 1.5.2 book - Part 14 of 181Mahmoud Samir Fayed
 

Ähnlich wie Working with TypeScript - A Concise Guide (20)

Angular2 for Beginners
Angular2 for BeginnersAngular2 for Beginners
Angular2 for Beginners
 
A Replay Approach to Software Validation
A Replay Approach to Software ValidationA Replay Approach to Software Validation
A Replay Approach to Software Validation
 
Angular2
Angular2Angular2
Angular2
 
Golang
GolangGolang
Golang
 
Hands on Session on Python
Hands on Session on PythonHands on Session on Python
Hands on Session on Python
 
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみたスマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
 
Python for Security Professionals
Python for Security ProfessionalsPython for Security Professionals
Python for Security Professionals
 
A la découverte de TypeScript
A la découverte de TypeScriptA la découverte de TypeScript
A la découverte de TypeScript
 
Lex tool manual
Lex tool manualLex tool manual
Lex tool manual
 
JSLounge - TypeScript 소개
JSLounge - TypeScript 소개JSLounge - TypeScript 소개
JSLounge - TypeScript 소개
 
Monitoring and Debugging your Live Applications
Monitoring and Debugging your Live ApplicationsMonitoring and Debugging your Live Applications
Monitoring and Debugging your Live Applications
 
CSV JSON and XML files in Python.pptx
CSV JSON and XML files in Python.pptxCSV JSON and XML files in Python.pptx
CSV JSON and XML files in Python.pptx
 
CoderDojo: Intermediate Python programming course
CoderDojo: Intermediate Python programming courseCoderDojo: Intermediate Python programming course
CoderDojo: Intermediate Python programming course
 
C++ Advanced Features
C++ Advanced FeaturesC++ Advanced Features
C++ Advanced Features
 
Modern C++
Modern C++Modern C++
Modern C++
 
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
App secforum2014 andrivet-cplusplus11-metaprogramming_applied_to_software_obf...
 
シェル芸でライフハック(特論)
シェル芸でライフハック(特論)シェル芸でライフハック(特論)
シェル芸でライフハック(特論)
 
Webinar alain-2009-03-04-clamav
Webinar alain-2009-03-04-clamavWebinar alain-2009-03-04-clamav
Webinar alain-2009-03-04-clamav
 
C++ Advanced Features
C++ Advanced FeaturesC++ Advanced Features
C++ Advanced Features
 
The Ring programming language version 1.5.2 book - Part 14 of 181
The Ring programming language version 1.5.2 book - Part 14 of 181The Ring programming language version 1.5.2 book - Part 14 of 181
The Ring programming language version 1.5.2 book - Part 14 of 181
 

Mehr von Oswald Campesato

Working with tf.data (TF 2)
Working with tf.data (TF 2)Working with tf.data (TF 2)
Working with tf.data (TF 2)Oswald Campesato
 
Introduction to TensorFlow 2 and Keras
Introduction to TensorFlow 2 and KerasIntroduction to TensorFlow 2 and Keras
Introduction to TensorFlow 2 and KerasOswald Campesato
 
Introduction to Deep Learning
Introduction to Deep LearningIntroduction to Deep Learning
Introduction to Deep LearningOswald Campesato
 
Introduction to TensorFlow 2
Introduction to TensorFlow 2Introduction to TensorFlow 2
Introduction to TensorFlow 2Oswald Campesato
 
Introduction to TensorFlow 2
Introduction to TensorFlow 2Introduction to TensorFlow 2
Introduction to TensorFlow 2Oswald Campesato
 
"An Introduction to AI and Deep Learning"
"An Introduction to AI and Deep Learning""An Introduction to AI and Deep Learning"
"An Introduction to AI and Deep Learning"Oswald Campesato
 
Introduction to Deep Learning, Keras, and Tensorflow
Introduction to Deep Learning, Keras, and TensorflowIntroduction to Deep Learning, Keras, and Tensorflow
Introduction to Deep Learning, Keras, and TensorflowOswald Campesato
 
Introduction to Deep Learning for Non-Programmers
Introduction to Deep Learning for Non-ProgrammersIntroduction to Deep Learning for Non-Programmers
Introduction to Deep Learning for Non-ProgrammersOswald Campesato
 
TensorFlow in Your Browser
TensorFlow in Your BrowserTensorFlow in Your Browser
TensorFlow in Your BrowserOswald Campesato
 
Deep Learning in Your Browser
Deep Learning in Your BrowserDeep Learning in Your Browser
Deep Learning in Your BrowserOswald Campesato
 
Deep Learning and TensorFlow
Deep Learning and TensorFlowDeep Learning and TensorFlow
Deep Learning and TensorFlowOswald Campesato
 
Introduction to Deep Learning and TensorFlow
Introduction to Deep Learning and TensorFlowIntroduction to Deep Learning and TensorFlow
Introduction to Deep Learning and TensorFlowOswald Campesato
 
Intro to Deep Learning, TensorFlow, and tensorflow.js
Intro to Deep Learning, TensorFlow, and tensorflow.jsIntro to Deep Learning, TensorFlow, and tensorflow.js
Intro to Deep Learning, TensorFlow, and tensorflow.jsOswald Campesato
 
Deep Learning and TensorFlow
Deep Learning and TensorFlowDeep Learning and TensorFlow
Deep Learning and TensorFlowOswald Campesato
 
Introduction to Deep Learning and Tensorflow
Introduction to Deep Learning and TensorflowIntroduction to Deep Learning and Tensorflow
Introduction to Deep Learning and TensorflowOswald Campesato
 
Deep Learning, Scala, and Spark
Deep Learning, Scala, and SparkDeep Learning, Scala, and Spark
Deep Learning, Scala, and SparkOswald Campesato
 
Deep Learning in your Browser: powered by WebGL
Deep Learning in your Browser: powered by WebGLDeep Learning in your Browser: powered by WebGL
Deep Learning in your Browser: powered by WebGLOswald Campesato
 
Deep Learning, Keras, and TensorFlow
Deep Learning, Keras, and TensorFlowDeep Learning, Keras, and TensorFlow
Deep Learning, Keras, and TensorFlowOswald Campesato
 

Mehr von Oswald Campesato (20)

Working with tf.data (TF 2)
Working with tf.data (TF 2)Working with tf.data (TF 2)
Working with tf.data (TF 2)
 
Introduction to TensorFlow 2 and Keras
Introduction to TensorFlow 2 and KerasIntroduction to TensorFlow 2 and Keras
Introduction to TensorFlow 2 and Keras
 
Introduction to Deep Learning
Introduction to Deep LearningIntroduction to Deep Learning
Introduction to Deep Learning
 
Introduction to TensorFlow 2
Introduction to TensorFlow 2Introduction to TensorFlow 2
Introduction to TensorFlow 2
 
Introduction to TensorFlow 2
Introduction to TensorFlow 2Introduction to TensorFlow 2
Introduction to TensorFlow 2
 
"An Introduction to AI and Deep Learning"
"An Introduction to AI and Deep Learning""An Introduction to AI and Deep Learning"
"An Introduction to AI and Deep Learning"
 
H2 o berkeleydltf
H2 o berkeleydltfH2 o berkeleydltf
H2 o berkeleydltf
 
Introduction to Deep Learning, Keras, and Tensorflow
Introduction to Deep Learning, Keras, and TensorflowIntroduction to Deep Learning, Keras, and Tensorflow
Introduction to Deep Learning, Keras, and Tensorflow
 
Introduction to Deep Learning for Non-Programmers
Introduction to Deep Learning for Non-ProgrammersIntroduction to Deep Learning for Non-Programmers
Introduction to Deep Learning for Non-Programmers
 
TensorFlow in Your Browser
TensorFlow in Your BrowserTensorFlow in Your Browser
TensorFlow in Your Browser
 
Deep Learning in Your Browser
Deep Learning in Your BrowserDeep Learning in Your Browser
Deep Learning in Your Browser
 
Deep Learning and TensorFlow
Deep Learning and TensorFlowDeep Learning and TensorFlow
Deep Learning and TensorFlow
 
Introduction to Deep Learning and TensorFlow
Introduction to Deep Learning and TensorFlowIntroduction to Deep Learning and TensorFlow
Introduction to Deep Learning and TensorFlow
 
Intro to Deep Learning, TensorFlow, and tensorflow.js
Intro to Deep Learning, TensorFlow, and tensorflow.jsIntro to Deep Learning, TensorFlow, and tensorflow.js
Intro to Deep Learning, TensorFlow, and tensorflow.js
 
Deep Learning and TensorFlow
Deep Learning and TensorFlowDeep Learning and TensorFlow
Deep Learning and TensorFlow
 
Introduction to Deep Learning and Tensorflow
Introduction to Deep Learning and TensorflowIntroduction to Deep Learning and Tensorflow
Introduction to Deep Learning and Tensorflow
 
Deep Learning, Scala, and Spark
Deep Learning, Scala, and SparkDeep Learning, Scala, and Spark
Deep Learning, Scala, and Spark
 
Deep Learning in your Browser: powered by WebGL
Deep Learning in your Browser: powered by WebGLDeep Learning in your Browser: powered by WebGL
Deep Learning in your Browser: powered by WebGL
 
Deep Learning, Keras, and TensorFlow
Deep Learning, Keras, and TensorFlowDeep Learning, Keras, and TensorFlow
Deep Learning, Keras, and TensorFlow
 
C++ and Deep Learning
C++ and Deep LearningC++ and Deep Learning
C++ and Deep Learning
 

Kürzlich hochgeladen

Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
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
 
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
 
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
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
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
 
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
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
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
 
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
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
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.
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
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
 

Kürzlich hochgeladen (20)

Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
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
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
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...
 
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...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
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...
 
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
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
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
 
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
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
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
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
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
 

Working with TypeScript - A Concise Guide

  • 1. Working with TypeScript Oswald Campesato Consultant/Training: www.iquarkt.com ocampesato@yahoo.com
  • 2. What is TypeScript? • Microsoft created TypeScript in October/2012 • Supports ES6 • Supports interfaces and sub-interfaces • Supports classes and subclasses • Optional type system • Angular 2 is written in Typescript https://scotch.io/tutorials/why-you-shouldnt-be-scared-of- typescript8
  • 3. More TypeScript Details • A compiled language (tsc compiler) • strong typing and also type inferencing • type checking during compile time • "minimal" extra compile time overhead • tsc transpiles ".ts" files into ".js" files • [sudo] npm install –g typescript // <- installs “tsc”
  • 4. Links with TypeScript Details • Official TypeScript website: http://www.typescriptlang.org/ • Typings: TypeScript Definition Manager: https://github.com/typings/typings Definitely Typed: 3rd-party TypeScript Definitions: http://definitelytyped.org/
  • 5. Browser Support for TypeScript • Browsers support only ECMA5 • TypeScript is transpiled to ECMA5 • ES6 is transpiled to ECMA5 • TypeScript playground: https://www.typescriptlang.org/play/ • tsc is the TypeScript compiler (can also use Babel)
  • 6. TypeScript Exposes 9 Types • Boolean • Number • String • Array • Tuple • Enum • Any • Void • Function
  • 7. Additions to TypeScript • Types • Classes • Annotations • Imports • language utilities (e.g. destructuring) • interfaces • inheritance • generics
  • 8. Simple Types in TypeScript • var isDone: boolean = false; • var height: number = 6; • var name: string = "dave"; • var myList:number[] = [1, 2, 3]; // option #1 • var myList:Array<number> = [1, 2, 3]; // option #2 • var changeMe: any = 4; • changeMe = ”I’m a string now"; • var myList:any[] = [1, true, ”pizza"];
  • 9. ECMA5 vs TypeScript Functions • ECMA5 version: • function add(a,b) { return a+b; } • add(1,4); // 5 • add(1,’4'); // 14 (valid in ECMA5) • TypeScript version: • function add(a:number, b:number) { return a+b; } • add(1,4); // 5 • add(1,’4'); // (error in TypeScript)
  • 10. Functions in TypeScript • msg is an argument of type string and return type is void in the myLogger function: • function myLogger(msg?:string): void { • console.log("My custom logger: “+msg); • } • Note: the trailing question mark (“?”) after msg indicates that msg is an optional argument
  • 11. Simple Iteration: Factorial • factorial(n) { • var prod = 1; • for(var i=1; i<=n; n++) { • prod *= i; • console.log(“factorial “+i+” = “+prod); • } • return prod; • } • console.log(“factorial 5 = “+factorial(5)); • console.log(“factorial 10 = “+factorial(10));
  • 12. Exercises: Iteration • 1) EvenP: calculate the product of the even integers between 1 and n • 2) Prime: check if the positive integer n is prime (its only divisors are 1 and itself) • 3) print the primes between 2 and 100 • 4) Goldbach’s conjecture: every even number greater than 2 can be written as a sum of two odd primes: write a function to show it’s true up to 100 (use #3) • 5) use #4 to find even numbers with multiple solutions, such as 14 (=3+11 = 7+7)
  • 13. Simple Recursion: Factorial • factorial(n) { • if(n <= 1) return 1; • else return n * factorial(n-1) • } • console.log(“factorial 5 = “+factorial(5)); • console.log(“factorial 10 = “+factorial(10));
  • 14. Tail Recursion: Factorial • factorial(n, prod) { • if(n <= 1) return prod; • else return factorial(n-1, n*prod) • } • console.log(“factorial 5 = “+factorial(5,1)); • console.log(“factorial 10 = “+factorial(10,1));
  • 15. Exercises: Recursion 1) use Euclid’s algorithm to find the GCD of two positive integers (GCD = Greatest Common Divisor) Example: GCD(10,24) = 2 2) use #1 to find the LCM of two positive integers (where LCM = Lowest Common Multiple) Note: LCM(a,b) = a*b/gcd(a,b) Example: LCM(10,24) = 120 3) Use recursion to calculate Fibonacci(20)
  • 16. Generics in TypeScript • Similar to a generic in other languages: • function identity<T>(arg: T): T { • return arg; • } • • // output has 'string' type (explicit/inferred): • var output = identity<string>("Dave"); • var output = identity("Dave");
  • 17. tsc: Transpiles TypeScript to ECMA5 • 1) version number: tsc –version • 2) compile the TS file app.ts: tsc app.ts (will generate app.js) • 3) watch for files changes in app.ts: a) tsc –-watch app.ts b) tsc –-watch –out bundle.js app.ts 4) tsc –help lists the available options
  • 18. Output from tsc --init • { • "compilerOptions": { • "module": "commonjs", • "target": "es3", • "noImplicitAny": false, • "outDir": "built", • "rootDir": ".", • "sourceMap": false • }, • "exclude": [ • "node_modules" • ] • } // ‘tsc‘ will now compile all TS files in directory
  • 19. Sample tsconfig.json for Angular 2 • { • "version": "1.7.5", • "compilerOptions": { • "emitDecoratorMetadata": true, • "experimentalDecorators": true, • "target": "es5", • "module": "system", • "moduleResolution": "node", • "removeComments": true, • "sourceMap": true, • "outDir": "dist" • }, • "exclude": [ • "node_modules" • ] • }
  • 20. Compilation with tsc • 1) create the following class in app.ts: class MyClass { } • 2) compile the previous class: tsc app.ts • 3) step #2 generates this code in app.js: var MyClass = (function () { function MyClass() { } return MyClass; })();
  • 21. Interfaces in TypeScript (1) interface IUser { fname: string; lname: string; weight?: number; // optional } function displayUser(user: IUser) { console.log("First name = "+user.fname); }
  • 22. Interfaces in TypeScript (2) interface IUser { fname: string; lname: string; weight?: number; // optional } // the following code works correctly: var aUser = {fname: "John", lname: "Smith", weight:200}; displayUser(aUser);
  • 23. ES6 Class versus TypeScript Class class ES6Class { // ES6 Class constructor(items) { // no type definition this.items = items; } } let mye6s = new ES6Class([1,2,3]); console.log(myes6s.items); class TSClass { // TypeScript Class items: string[]; constructor(items: string[]) { this.items = items; } } let myts = new TSClass([1,2,3]); console.log(myts.items);
  • 24. Classes in TypeScript (1) class User { fname: string; lname: string; weight: number; constructor(fname:string, lname:string, weight:number) { this.fname = fname; this.lname = lname; this.weight = weight; } fullname():string { return (this.fname+" "+this.lname+" weighs "+this.weight); } }
  • 25. Classes in TypeScript (2) var u1:User, u2:User; u1 = new User("Jane", "Smith"); u2 = new User("John", "Jones"); console.log("user1 = "+u1.fullname()); console.log("user2 = "+u2.fullname());
  • 26. JSON to a TypeScript Class (1) var people = [ {fname:"Jane",lname:"Smith",zip:"94043"}, {fname:"John",lname:"Jones",zip:"94539"}, {fname:"Dave",lname:"Starr",zip:"67800"} ]
  • 27. JSON to a TypeScript Class (2) class Person { //unnecessary because constructor specifies “public”: //fname:string; //lname:string; //zip:string; constructor(public fname:string, public lname:string, public zip:string) { this.fname = fname; this.lname = lname; this.zip = zip; } }
  • 28. JSON to a TypeScript Class (3) var TSPeople = [ new Person("Jane","Smith","94043"), new Person("John","Jones","94539"), new Person("Dave","Starr","67800") ];
  • 29. Implementing TypeScript Interfaces (1) Interface IRect = { width: number; height: number; perimeter: number; area: number; }
  • 30. Implementing TypeScript Interfaces (2) class Rectangle implements IRect { constructor(public width:number, public height:number) { this.width = width; this.height = height; } public getArea() { return width*height } public getPerimeter() { return 2*(width+height) } }
  • 31. Implementing TypeScript Interfaces (3) var rect1 = new Rectangle(5,10); console.log(“area = “+rect1.getArea()); console.log(“perimeter = “+rect1.getPerimeter()); var rect2 = new Rectangle(12,20); console.log(“area = “+rect2.getArea()); console.log(“perimeter = “+rect2.getPerimeter());
  • 32. TypeScript Subclasses class Square extends Rectangle { constructor(public side:number, width:number, height:number) { super(width, height); this.side = side; } area(): void {} perimeter(): void {} } var square1 = new Square(20); console.log("area = "+square1.getArea()); console.log("perimeter = "+square1.getPerimeter());
  • 33. Exercises for Interfaces/Classes 1) Define an interface IPerson that contains a first name, last name, and zip code 2) Create a Person2 class that implements IPerson: class Person2 implements IPerson { … } 3) Modify IPerson so that it contains an optional weight property
  • 34. IDEs for TypeScript WebStorm IDE (30-day trial) Visual Studio Code (free and cross-platform) TypEcs (TypeScript IDE for Eclipse): http://typecsdev.com/ http://definitelytyped.org/directory/tools.html
  • 35. TypeScript Versions • https://github.com/Microsoft/TypeScript/wiki/Ro admap • Navigate to website to see list of features for: • TS 2.1 • TS 2.0 • TS 1.9 • TS 1.8 • TS 1.7 • TS 1.6
  • 36. Recent/Upcoming Books and Training 1) HTML5 Canvas and CSS3 Graphics (2013) 2) jQuery, CSS3, and HTML5 for Mobile (2013) 3) HTML5 Pocket Primer (2013) 4) jQuery Pocket Primer (2013) 5) HTML5 Mobile Pocket Primer (2014) 6) D3 Pocket Primer (2015) 7) Python Pocket Primer (2015) 8) SVG Pocket Primer (2016) 9) CSS3 Pocket Primer (2016) 10) Angular 2 Pocket Primer (2016)