SlideShare a Scribd company logo
Introduction to:
TypeScript
Frontend Development Consultancy
Tomas Corral Casas
Head of Frontend Technologies and Academy
Consulting for:
Who created
TypeScript?
Anders
Hejlsberg
What is TypeScript?
“ TypeScript is a
typed superset of JavaScript
that compiles to plain JavaScript. ”
TypeScript
Typing, scopes…
ES7
Decorators, async/await...
ES6
Classes, Modules...
ES5
Writing new code
Maintaining old code
Understanding code
5%25%70%
What does a developer spend time on?
Before Typescript
Hungarian Notation
Hungarian notation
Prefix Type Example
b Boolean var bIsVisible = true;
e DOM element var eHeader = document.getElementById('header');
f Function var fCallback = function () { … };
n Number var nSides = 4;
o Object var oPoint = new Point(200, 345);
a Array var aNames = ['Luke', 'Nick', 'David'];
s String var sUrl = 'http://www.google.com';
$ jQuery var $Header = $('#header);
Prefix Type Example
_ Private var _transformData = function (data) { … return result; }
Public var render = function () { … };
Protected
Scope
JSDoc comments
@private
@typedef
@param {string} color
@param {LACE_TYPES}
type
@public
@access
@protected
@package
@class
@constructor
@constant
@enum
JSDoc comments
Why types are so important?
Why types are so important?
Source
Code AST BytecodeParser
Bytecode
Generator
JIT Compiler
Garbage Collector
Core1
Interpreter
Machine
Code
Execution
Bytecode
Machine
Code
Additional
Cores
Basic Types
Union voidnull undefined
boolean number anynever
Tuplestring ArrayObject
Type assertions
Basic Types - Inferred
let month = 5;
let name = 'Mik';
let isVisible = false;
let cities = ['New York', 'Oxford', 'Valladolid'];
let person = {
firstName: 'Gerardo',
lastName: 'Abelardo'
};
Basic Types - Explicit
let month: number;
let name: string;
let isVisible: boolean;
let person: object;
let employee: any;
let cities: string[];
let customers: Array<any>;
let value: null;
let value2: undefined;
let value3: void;
let address: [string, number, string, string];
Basic Types
let someValue: any = "this is a string";
let strLength: number = (someValue as string).length;
let strLength2: number = (<string>someValue).length;
Type Assertions
Basic Types - Union
let area: string| undefined = property('area');
let element: HTMLElement | null = document.getElementById('passion');
let menu: Array<Link | Divider> = getMenu();
How TypeScript type-
checking works?
A.K.A “duck typing” or “structural
subtyping”.
Type-checking focuses on the shape
that values have.
Enums
String EnumsNumber Enums
Number Enums
enum WeatherType {
Sunny,
Cloudy,
Rainy,
Storm,
Frost,
Nightly
}
enum WeatherType {
Sunny = 1,
Cloudy = 2,
Rainy = 3,
Storm = 4,
Frost = 5,
Nightly = 6
}
Number Enums - Usage
class Weather {
getWeatherIcon(weatherType: WeatherType) {
switch (weatherType) {
case WeatherType.Sunny: return 'weather_sunny';
case WeatherType.Cloudy: return 'weather_cloudy';
case WeatherType.Rainy: return 'weather_rain';
case WeatherType.Storm: return 'weather_storm';
case WeatherType.Frost: return 'weather_frost';
case WeatherType.Nightly: return 'weather_nightly';
}
}
}
String Enums
enum WeatherType {
Sunny = 'weather_sunny',
Cloudy = 'weather_cloudy',
Rainy = 'weather_rain',
Storm = 'weather_storm',
Frost = 'weather_frost',
Nightly = 'weather_nightly',
}
Functions
Function Types Overloading
Function Types 1/3
function add(x: number, y: number): number {
return x + y;
}
function multiply(x: number, y: number): number {
return x * y;
}
let myAdd: (x: number, y: number) => number = add;
type twoOperandsType = (x: number, y: number) => number;
let myMultiply: twoOperandsType = multiply;
Function Types 2/3
function buildName(firstName: string, lastName?: string) {
if (lastName) { return `${firstName} ${lastName}`; }
else { return firstName; }
}
function buildAddress(street: string, postalCode: string = 'UNDEFINED') {
if (postalCode) { return `${street} ${postalCode}`; }
else { return street; }
}
Function Types 3/3
type buildStringOneOrMoreArguments = (x: string, y: string) => string;
const buildName1: buildStringOneOrMoreArguments = buildName;
const buildAddress1: buildStringOneOrMoreArguments = buildAddress;
function buildFamily(father: string, ...restOfFamily: string[]) {
return `${father} ${restOfFamily.join(" ")}`;
}
This
const mother = {
name: 'Maria',
sons: [
'Lucho',
'Mauro'
],
daughters: [
'Silvia',
'Romani'
],
getChildren(): string[] {
return this.sons.concat(this.daughters);
}
};
const father = {
name: 'Manolo',
sons: [
'Lucho',
'Mauro'
],
daughters: [
'Silvia',
'Romani'
],
getChildren(this: void) { // Avoid using this.
return this.sons.concat(this.daughters);
}
}
Arrow Function
let deck = {
suits: ["hearts", "spades", "clubs", "diamonds"],
cards: Array(52),
createCardPicker: function() {
return () => {
let pickedCard = Math.floor(Math.random() * 52);
let pickedSuit = Math.floor(pickedCard / 13);
return {
suit: this.suits[pickedSuit],
card: pickedCard % 13
};
}
}
};
Overloading
type propertiesObject = { [name: string]: any };
const properties: propertiesObject = {};
function property(propertyName: string, defaultValue: any ): any;
function property(propertyName: string): any | undefined;
function property(propertyName: string, defaultValue?: any) {
if (defaultValue) {
properties[propertyName] = defaultValue;
}
return properties[propertyName];
}
Interfaces
interface
implements
Interfaces
interface TreeLink {
type: string;
title: string;
url: string;
isCurrent: boolean;
preferences: any;
children: TreeLink[];
}
const treeLink: TreeLink = {
type: 'external',
title: 'Google',
url: 'http://www.google.nl',
isCurrent: false,
preferences: {
navIcon: 'accounts'
},
children: []
};
Implements
interface Flyable { fly: () => void }
interface Quackable { quack: () => void; }
class Duck implements Flyable, Quackable {
fly() { console.log('Fly, Fly, Fly'); }
quack() { console.log('Quack, Quack'); }
}
class Turkey implements Flyable {
fly() { console.log('Ufff!'); }
}
Classes
readonlypublic private protected
getters setters
static methods and properties
class abstractextends implements
Classes
class Animal {
name: string;
constructor(name: string) {
this.name = name;
}
}
class Animal {
constructor(
public name: string
) {}
}
Abstract Classes
abstract class Animal {
constructor(
public readonly name: string
) {}
abstract makeSound(): void;
abstract move(): void;
abstract getOffspring(): void;
}
abstract class Mammal extends Animal{
constructor(
public readonly name: string,
public readonly legs: number
) {
super(name);
}
}
Inheritance 1/3
class Whale extends Mammal {
constructor(){ super('Whale', 0); }
makeSound() { console.log('waaoaoooooooooooaoaoo'); }
move() { console.log('Swim, Swim, Swim, Swim, Swim!'); }
getOffspring() { console.log('Get birth a calf!'); }
}
Inheritance 2/3
class Dog extends Mammal {
constructor() { super('Dog', 4); }
makeSound() { console.log('Woof, Woof, Woof!'); }
move() { console.log('Walk, Walk, Walk!'); }
getOffspring() { console.log('Get birth a dozen puppies!'); }
}
Inheritance 3/3
class Platypus extends Mammal {
constructor() { super('Platypus', 4); }
makeSound() { console.log('hrrrrrrrrrrrh'); }
move() { console.log('Swim, Swim, Walk, Walk!'); }
getOffspring() { console.log('Put eggs and wait!'); }
}
Generics
Generic Types Generic Classes
Generics
function echo<T>(arg: T): T {
console.log(arg);
return arg;
}
echo('19th October');
echo<string>('Friday');
echo<number>(19);
Generic Types
function identity<T>(arg: T): T {
return arg;
}
let myIdentity: <T>(arg: T) => T = identity;
let myIdentity2: <U>(arg: U) => U = identity;
Generic Classes
class Operator<T> {
initialValue: T;
operation: (x: T, y: T) => T;
}
const numAdder = new Operator<number>();
numAdder.initValue = 10;
numAdder.operation = function(x, y) {
return this.initValue + x + y;
};
const strConc = new Operator<string>();
strConc.initValue = '';
strConc.operation = function (x, y) {
return `${this.initValue} ${x} ${y}`;
};
Modules and Namespaces
export import
Default exports Working with other libraries
Namespacing Multi-file namespace
Export
export class Cat {
constructor(private name: string, private legs: number){}
}
export default {
getCatInstance(name: string, legs: number) {
return new Cat(name, legs);
}
}
Import
import { Cat } from './Cat';
import { getCatInstance } from './utils';
Namespaces
export namespace Shapes {
export class Triangle { /* ... */ }
export class Square { /* ... */ }
}
import * as shapes from "./shapes";
let t = new shapes.Shapes.Triangle(); // shapes.Shapes?
Introduction to TypeScript
Thanks.

More Related Content

What's hot (20)

PPTX
PHP in 2018 - Q4 - AFUP Limoges
✅ William Pinaud
 
PDF
Introduction to Rust
Jean Carlo Machado
 
PDF
Your code is not a string
Ingvar Stepanyan
 
PDF
Rakudo
awwaiid
 
PDF
PHP Language Trivia
Nikita Popov
 
PDF
Swift internals
Jung Kim
 
KEY
groovy & grails - lecture 2
Alexandre Masselot
 
ODP
EcmaScript 6
Manoj Kumar
 
PDF
Introdução ao Perl 6
garux
 
PDF
Functional Programming with Groovy
Arturo Herrero
 
PDF
Rust concurrency tutorial 2015 12-02
nikomatsakis
 
PDF
Javascript basics
Fin Chen
 
PDF
Perl 6 in Context
lichtkind
 
PDF
C++ Programming - 12th Study
Chris Ohk
 
PDF
LetSwift RxSwift 시작하기
Wanbok Choi
 
PDF
C++ Programming - 9th Study
Chris Ohk
 
PDF
Explaining ES6: JavaScript History and What is to Come
Cory Forsyth
 
PDF
Static Optimization of PHP bytecode (PHPSC 2017)
Nikita Popov
 
PDF
ECMAScript2015
qmmr
 
PDF
Fantastic DSL in Python
kwatch
 
PHP in 2018 - Q4 - AFUP Limoges
✅ William Pinaud
 
Introduction to Rust
Jean Carlo Machado
 
Your code is not a string
Ingvar Stepanyan
 
Rakudo
awwaiid
 
PHP Language Trivia
Nikita Popov
 
Swift internals
Jung Kim
 
groovy & grails - lecture 2
Alexandre Masselot
 
EcmaScript 6
Manoj Kumar
 
Introdução ao Perl 6
garux
 
Functional Programming with Groovy
Arturo Herrero
 
Rust concurrency tutorial 2015 12-02
nikomatsakis
 
Javascript basics
Fin Chen
 
Perl 6 in Context
lichtkind
 
C++ Programming - 12th Study
Chris Ohk
 
LetSwift RxSwift 시작하기
Wanbok Choi
 
C++ Programming - 9th Study
Chris Ohk
 
Explaining ES6: JavaScript History and What is to Come
Cory Forsyth
 
Static Optimization of PHP bytecode (PHPSC 2017)
Nikita Popov
 
ECMAScript2015
qmmr
 
Fantastic DSL in Python
kwatch
 

Similar to Introduction to TypeScript (20)

PDF
Back to the Future with TypeScript
Aleš Najmann
 
PDF
Introduction to typescript
Mario Alexandro Santini
 
PPTX
Why TypeScript?
FITC
 
PPTX
Type Driven Development with TypeScript
Garth Gilmour
 
PDF
Typescript is the best
GlobalLogic Ukraine
 
PDF
Typescript is the best by Maxim Kryuk
GlobalLogic Ukraine
 
PPTX
Introduction to TypeScript
KeithMurgic
 
PPTX
Type script is awesome
KeithMurgic
 
PDF
Types For Frontend Developers
Jesse Williamson
 
PPTX
Typescript - A developer friendly javascript
pradiphudekar
 
PPTX
TypeScript by Howard
LearningTech
 
PPTX
Howard type script
LearningTech
 
PPTX
Type script by Howard
LearningTech
 
PPTX
All You Need to Know About Type Script
Folio3 Software
 
PDF
TypeScript Best Practices
felixbillon
 
PPTX
TypeScript
Oswald Campesato
 
PPTX
Typescript barcelona
Christoffer Noring
 
PPT
Learning typescript
Alexandre Marreiros
 
PDF
Static types on javascript?! Type checking approaches to ensure healthy appli...
Arthur Puthin
 
PDF
A la découverte de TypeScript
Denis Voituron
 
Back to the Future with TypeScript
Aleš Najmann
 
Introduction to typescript
Mario Alexandro Santini
 
Why TypeScript?
FITC
 
Type Driven Development with TypeScript
Garth Gilmour
 
Typescript is the best
GlobalLogic Ukraine
 
Typescript is the best by Maxim Kryuk
GlobalLogic Ukraine
 
Introduction to TypeScript
KeithMurgic
 
Type script is awesome
KeithMurgic
 
Types For Frontend Developers
Jesse Williamson
 
Typescript - A developer friendly javascript
pradiphudekar
 
TypeScript by Howard
LearningTech
 
Howard type script
LearningTech
 
Type script by Howard
LearningTech
 
All You Need to Know About Type Script
Folio3 Software
 
TypeScript Best Practices
felixbillon
 
TypeScript
Oswald Campesato
 
Typescript barcelona
Christoffer Noring
 
Learning typescript
Alexandre Marreiros
 
Static types on javascript?! Type checking approaches to ensure healthy appli...
Arthur Puthin
 
A la découverte de TypeScript
Denis Voituron
 
Ad

More from Tomas Corral Casas (9)

PPTX
Mikado method
Tomas Corral Casas
 
PDF
Welovejs AngularJS
Tomas Corral Casas
 
PPTX
Testea y aumenta tu karma
Tomas Corral Casas
 
PPTX
Coderdojo bcn 12_10_2013
Tomas Corral Casas
 
PPS
Lo que los desarrolladores web deberían saber
Tomas Corral Casas
 
ODP
Hydra.js modula tu código
Tomas Corral Casas
 
PPTX
Less is more
Tomas Corral Casas
 
PPTX
Design patterns in Javascript
Tomas Corral Casas
 
PDF
Automatización Unit Testing Javascript
Tomas Corral Casas
 
Mikado method
Tomas Corral Casas
 
Welovejs AngularJS
Tomas Corral Casas
 
Testea y aumenta tu karma
Tomas Corral Casas
 
Coderdojo bcn 12_10_2013
Tomas Corral Casas
 
Lo que los desarrolladores web deberían saber
Tomas Corral Casas
 
Hydra.js modula tu código
Tomas Corral Casas
 
Less is more
Tomas Corral Casas
 
Design patterns in Javascript
Tomas Corral Casas
 
Automatización Unit Testing Javascript
Tomas Corral Casas
 
Ad

Recently uploaded (20)

PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PPTX
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 

Introduction to TypeScript

  • 2. Frontend Development Consultancy Tomas Corral Casas Head of Frontend Technologies and Academy Consulting for:
  • 6. “ TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. ”
  • 8. Writing new code Maintaining old code Understanding code 5%25%70% What does a developer spend time on?
  • 11. Hungarian notation Prefix Type Example b Boolean var bIsVisible = true; e DOM element var eHeader = document.getElementById('header'); f Function var fCallback = function () { … }; n Number var nSides = 4; o Object var oPoint = new Point(200, 345); a Array var aNames = ['Luke', 'Nick', 'David']; s String var sUrl = 'http://www.google.com'; $ jQuery var $Header = $('#header);
  • 12. Prefix Type Example _ Private var _transformData = function (data) { … return result; } Public var render = function () { … }; Protected Scope
  • 14. @private @typedef @param {string} color @param {LACE_TYPES} type @public @access @protected @package @class @constructor @constant @enum JSDoc comments
  • 15. Why types are so important?
  • 16. Why types are so important? Source Code AST BytecodeParser Bytecode Generator JIT Compiler Garbage Collector Core1 Interpreter Machine Code Execution Bytecode Machine Code Additional Cores
  • 17. Basic Types Union voidnull undefined boolean number anynever Tuplestring ArrayObject Type assertions
  • 18. Basic Types - Inferred let month = 5; let name = 'Mik'; let isVisible = false; let cities = ['New York', 'Oxford', 'Valladolid']; let person = { firstName: 'Gerardo', lastName: 'Abelardo' };
  • 19. Basic Types - Explicit let month: number; let name: string; let isVisible: boolean; let person: object; let employee: any; let cities: string[]; let customers: Array<any>; let value: null; let value2: undefined; let value3: void; let address: [string, number, string, string];
  • 20. Basic Types let someValue: any = "this is a string"; let strLength: number = (someValue as string).length; let strLength2: number = (<string>someValue).length; Type Assertions
  • 21. Basic Types - Union let area: string| undefined = property('area'); let element: HTMLElement | null = document.getElementById('passion'); let menu: Array<Link | Divider> = getMenu();
  • 23. A.K.A “duck typing” or “structural subtyping”. Type-checking focuses on the shape that values have.
  • 25. Number Enums enum WeatherType { Sunny, Cloudy, Rainy, Storm, Frost, Nightly } enum WeatherType { Sunny = 1, Cloudy = 2, Rainy = 3, Storm = 4, Frost = 5, Nightly = 6 }
  • 26. Number Enums - Usage class Weather { getWeatherIcon(weatherType: WeatherType) { switch (weatherType) { case WeatherType.Sunny: return 'weather_sunny'; case WeatherType.Cloudy: return 'weather_cloudy'; case WeatherType.Rainy: return 'weather_rain'; case WeatherType.Storm: return 'weather_storm'; case WeatherType.Frost: return 'weather_frost'; case WeatherType.Nightly: return 'weather_nightly'; } } }
  • 27. String Enums enum WeatherType { Sunny = 'weather_sunny', Cloudy = 'weather_cloudy', Rainy = 'weather_rain', Storm = 'weather_storm', Frost = 'weather_frost', Nightly = 'weather_nightly', }
  • 29. Function Types 1/3 function add(x: number, y: number): number { return x + y; } function multiply(x: number, y: number): number { return x * y; } let myAdd: (x: number, y: number) => number = add; type twoOperandsType = (x: number, y: number) => number; let myMultiply: twoOperandsType = multiply;
  • 30. Function Types 2/3 function buildName(firstName: string, lastName?: string) { if (lastName) { return `${firstName} ${lastName}`; } else { return firstName; } } function buildAddress(street: string, postalCode: string = 'UNDEFINED') { if (postalCode) { return `${street} ${postalCode}`; } else { return street; } }
  • 31. Function Types 3/3 type buildStringOneOrMoreArguments = (x: string, y: string) => string; const buildName1: buildStringOneOrMoreArguments = buildName; const buildAddress1: buildStringOneOrMoreArguments = buildAddress; function buildFamily(father: string, ...restOfFamily: string[]) { return `${father} ${restOfFamily.join(" ")}`; }
  • 32. This const mother = { name: 'Maria', sons: [ 'Lucho', 'Mauro' ], daughters: [ 'Silvia', 'Romani' ], getChildren(): string[] { return this.sons.concat(this.daughters); } }; const father = { name: 'Manolo', sons: [ 'Lucho', 'Mauro' ], daughters: [ 'Silvia', 'Romani' ], getChildren(this: void) { // Avoid using this. return this.sons.concat(this.daughters); } }
  • 33. Arrow Function let deck = { suits: ["hearts", "spades", "clubs", "diamonds"], cards: Array(52), createCardPicker: function() { return () => { let pickedCard = Math.floor(Math.random() * 52); let pickedSuit = Math.floor(pickedCard / 13); return { suit: this.suits[pickedSuit], card: pickedCard % 13 }; } } };
  • 34. Overloading type propertiesObject = { [name: string]: any }; const properties: propertiesObject = {}; function property(propertyName: string, defaultValue: any ): any; function property(propertyName: string): any | undefined; function property(propertyName: string, defaultValue?: any) { if (defaultValue) { properties[propertyName] = defaultValue; } return properties[propertyName]; }
  • 36. Interfaces interface TreeLink { type: string; title: string; url: string; isCurrent: boolean; preferences: any; children: TreeLink[]; } const treeLink: TreeLink = { type: 'external', title: 'Google', url: 'http://www.google.nl', isCurrent: false, preferences: { navIcon: 'accounts' }, children: [] };
  • 37. Implements interface Flyable { fly: () => void } interface Quackable { quack: () => void; } class Duck implements Flyable, Quackable { fly() { console.log('Fly, Fly, Fly'); } quack() { console.log('Quack, Quack'); } } class Turkey implements Flyable { fly() { console.log('Ufff!'); } }
  • 38. Classes readonlypublic private protected getters setters static methods and properties class abstractextends implements
  • 39. Classes class Animal { name: string; constructor(name: string) { this.name = name; } } class Animal { constructor( public name: string ) {} }
  • 40. Abstract Classes abstract class Animal { constructor( public readonly name: string ) {} abstract makeSound(): void; abstract move(): void; abstract getOffspring(): void; } abstract class Mammal extends Animal{ constructor( public readonly name: string, public readonly legs: number ) { super(name); } }
  • 41. Inheritance 1/3 class Whale extends Mammal { constructor(){ super('Whale', 0); } makeSound() { console.log('waaoaoooooooooooaoaoo'); } move() { console.log('Swim, Swim, Swim, Swim, Swim!'); } getOffspring() { console.log('Get birth a calf!'); } }
  • 42. Inheritance 2/3 class Dog extends Mammal { constructor() { super('Dog', 4); } makeSound() { console.log('Woof, Woof, Woof!'); } move() { console.log('Walk, Walk, Walk!'); } getOffspring() { console.log('Get birth a dozen puppies!'); } }
  • 43. Inheritance 3/3 class Platypus extends Mammal { constructor() { super('Platypus', 4); } makeSound() { console.log('hrrrrrrrrrrrh'); } move() { console.log('Swim, Swim, Walk, Walk!'); } getOffspring() { console.log('Put eggs and wait!'); } }
  • 45. Generics function echo<T>(arg: T): T { console.log(arg); return arg; } echo('19th October'); echo<string>('Friday'); echo<number>(19);
  • 46. Generic Types function identity<T>(arg: T): T { return arg; } let myIdentity: <T>(arg: T) => T = identity; let myIdentity2: <U>(arg: U) => U = identity;
  • 47. Generic Classes class Operator<T> { initialValue: T; operation: (x: T, y: T) => T; } const numAdder = new Operator<number>(); numAdder.initValue = 10; numAdder.operation = function(x, y) { return this.initValue + x + y; }; const strConc = new Operator<string>(); strConc.initValue = ''; strConc.operation = function (x, y) { return `${this.initValue} ${x} ${y}`; };
  • 48. Modules and Namespaces export import Default exports Working with other libraries Namespacing Multi-file namespace
  • 49. Export export class Cat { constructor(private name: string, private legs: number){} } export default { getCatInstance(name: string, legs: number) { return new Cat(name, legs); } }
  • 50. Import import { Cat } from './Cat'; import { getCatInstance } from './utils';
  • 51. Namespaces export namespace Shapes { export class Triangle { /* ... */ } export class Square { /* ... */ } } import * as shapes from "./shapes"; let t = new shapes.Shapes.Triangle(); // shapes.Shapes?

Editor's Notes

  • #2: Before starting ask the people: Who has some experience with TypeScript? Who used TypeScript in personal projects? Who is used TypeScript professionally in a daily basis? On clicking one time this slide moves to the speaker presentation slide
  • #3: This slide shows my face at the beginning without clicking anything. On clicking: 1 - Shows my name and position. Tomas Corral Casas, Head of Frontend Technologies and Academy 2 - Shows the company I am working for: Passionate People where we do Frontend Development Consultancy 3 - Shows the company I am working on: Backbase. Remark the technologies we are actually using (TypeScript, Angular 6, RxJS) 4 - Moves to the next slide - Who created TypeScript?
  • #4: Shows the question - Who created TypeScript? On clicking it moves to the next slide when we can see only an empty slide.
  • #5: On clicking: 1 - It shows the creator of TypeScript . Anders Hejlsberg, Danish Creator of Delphi, Turbo Pascal and C# 2 - Shows Microsoft Logo 3- Moves to the next slide where we can see the question What is TypeScript?
  • #6: On clicking it will go to the next slide where we can see the answer. TypeScript is a typed superset of JavaScript that compiles to plain JavaScript.
  • #7: It shows the answer right away. TypeScript is a TYPED SUPERSET of Javascript THAT COMPILES to plain Javascript On clicking we move to the next slide where we can see an empty slide.
  • #8: In this slide we have to explain that being a superset means that it all starts with Javascript and ends with Javascript. The reason to exist is to add features that will be available in the future, or not, but that allows to structure our code in a more scalable way. On clicking: 1- Shows ES5 circle 2 - Shows ES6 classes, modules 3 - Shows ES7 Decorators, async/await… 4 - TypeScript - Typing, scopes. 5 - Moves to the next slide where we can see a question: What does a developer spend time on?
  • #9: https://blogs.msdn.microsoft.com/peterhal/2006/01/04/what-do-programmers-really-do-anyway-aka-part-2-of-the-yardstick-saga/ It shows the question What does a developer spend time on? On clicking: 1- The green block that represents 5% slides into the view from left side. (Ask the people what do they think this is about), when they answered click again. 2- Writing new code will slide in. 3- The blue block that represents 25% slides into the view from left side. (Ask the people what do they think this is about), when they answered click again. 4- Maintaining old code will slide in. 5- The purple block that represents 70% slides into the view from left side. (Ask the people what do they think this is about), when they answered click again. 6- Understanding code will slide in. 7 - Moves to the next slide - Before TypeScript
  • #10: https://en.wikipedia.org/wiki/Hungarian_notation https://humanwhocodes.com/blog/2006/11/01/the-case-against-hungarian-notation-in-javascript/ Shows two primitive silhouettes and the text Before TypeScript. On Click: Navigates to the slide where it shows Hungarian Notation
  • #11: It shows the sentence Hungarian Notation - Ask the audience how many people knows what is the hungarian notation. Ask the audience how many people actually used it and how many are still using it. On clicking it shows the next slide where we can see a few prefixes used in hungarian notation.
  • #12: https://en.wikipedia.org/wiki/Hungarian_notation https://humanwhocodes.com/blog/2006/11/01/the-case-against-hungarian-notation-in-javascript/ It shows a table with prefixes, type that the prefix is related to and an example: B -> Boolean -> var bIsVisible = true E -> Dom Element -> var eHeader = document.getElementById(‘header’); F -> Function -> var fCallback = function () {}; N -> Number -> var nSides = 4; O -> Object -> var oPoint = new Point(200, 345); A -> Array -> var aNames = [‘Luke’, ‘Nick’, ‘David’] S -> String -> var sUrl = ‘http://www.google.com’ $ -> jQuery -> var $Header = $(‘#header’) On clicking it goes to the next slide where the are represented the Scope, Private, Public y Protected.
  • #13: https://gist.github.com/tcorral/b5de0a318a09cda27d2830a813e5e8a6 It shows the Scope title and a table with prefix, type and example. The first line is and underscore used to represent private scope access var _transformData=function(data) { } The second line is empty because it represents everything public - var render = function () {}; The third is the protected but there was not protected. On clicking it goes to the next slide where we are going to discuss JSDOC comments
  • #14: https://en.wikipedia.org/wiki/Hungarian_notation https://humanwhocodes.com/blog/2006/11/01/the-case-against-hungarian-notation-in-javascript/
  • #15: https://en.wikipedia.org/wiki/Hungarian_notation https://humanwhocodes.com/blog/2006/11/01/the-case-against-hungarian-notation-in-javascript/ It shows only the title when we get in this slide: This doesn’t requires much explanation just name private, class, public, enum, protected, param, typedef. On clicking: 1- Shows the list of comments. 2- It goes to the next slide when we can see an exclamation mark and the question. Why types are so important?
  • #16: It shows the question why types are so important. Ask the audience if they know why types are so important in Javascript? On Clicking it goes to the next slide where it shows two blocks (Core 1, Other Cores)
  • #17: On Clicking: 1 - Source code slides in 2 - Parser slides in 3 - AST (Abstract Syntax Tree) https://astexplorer.net/ 4 - ByteCode generator (Browser) - Converts to ByteCode. 5 - ByteCode result 6 - Execution - Where the code can be interpreted or executed using machine code (Assembler) 7 - Shows the bytecode to the aditional cores 8 - Jit Compiler and Garbage Collector 9 - Arrow Machine Code. 10 - Two squares in red are shown grouping the things that can go wrong. 11 - It will navigate to Basic Types where we can only see the title Explain the audience and show the examples. Code that changes the type of a variable cannot be traced and it will be interpreted all the time instead of being pre-compiled in bytecode https://jsperf.com/js-best-practices-jit-1 https://jsperf.com/js-best-practices-jit-2 https://jsperf.com/js-best-practices-jit-3 https://jsperf.com/js-best-practices-jit-4 https://www.youtube.com/watch?v=p-iiEDtpy6I
  • #18: It shows the Basic Types only. On clicking: 1- All the types are shown 2- Moves to the next slide where we can see how TypeScript infers the types. Basic Types - Inferred. https://www.typescriptlang.org/docs/handbook/basic-types.html
  • #19: Shows Basic Types - Inferred and a black box. On clicking: 1- Let month = 5; 2 - let name = ‘Mik’; 3 - let isVisible = false; 4 - let cities = [‘New York’, ‘Oxford’, ‘Valladolid’]; 5 - let person = { 6 - firstName: ‘Gerardo’, 7 - lastName: ‘Abelardo’ 8- } 9 - Navigates to Basic Types Explicit. Explain that inferring works for primitives but that can be tricky and give problems if we want to use objects. Cities will only be an array of three strings. Person will be only an object that cannot be extended https://www.typescriptlang.org/play/index.html Use it to show some examples.
  • #20: It shows Basic Types - Explicit title and three black boxes. On clicking: 1 - let month: number; 2 - let name: string; 3 - let isVisible: boolean; 4 - let person: object; 5 - let employee: any; 6 - let cities: string[]; 7- let customers: Array<any>; 8- let value:null; 9- let value2: undefined; 10- let value3: void; 11 - let address: [string, number, string, string]; (This is a Tuple) 12 - Navigates to Basic Types - Type Assertions https://www.typescriptlang.org/play/index.html Use it to show some examples.
  • #21: It shows Basic Types - Type Assertions title and a black-box On click: 1 - let someValue: any = "this is a string"; 2- let strLength: number = (someValue as string).length; 3- let strLength2: number = (<string>someValue).length; 4- Navigates to Basic Types Union Explain that this is used when you really know what type are you getting but that could be anything else because the type was to broad but you need to use it and know the methods or properties or if you need to use it as an argument of a method or function that expects an especific type. https://www.typescriptlang.org/play/index.html Use it to show some examples.
  • #22: It shows the title Basic Types - Union and a black box. On clicking: 1- let area: string| undefined = property('area'); 2- let element: HTMLElement | null = document.getElementById('passion'); 3- let menu: Array<Link | Divider> = getMenu(); 4 - Navigates to the next slide where it shows the question How TypeScript type-checking works? Explain that unions is used when one type can be more than one type. https://www.typescriptlang.org/play/index.html Use it to show some examples.
  • #23: It shows the question How TypeScript type-checking works? On clicking it goes to the next slide where it shows Type-checking focuses on the shape that values have.
  • #24: It shows Type-checking focuses on the shape that values have. On clicking: 1- It shows a duck. 2- It shows the message A.K.A “duck typing” or “structural subtyping”. 3- It navigates to the Enums slide If it resembles what it’s expected then the type is accepted. “If it looks like a duck and quacks like a duck, it's a duck”
  • #25: It shows Enums title and two subtitles (Number Enums and String Enums) On clicking it navigates to Number Enums and two black boxes.
  • #26: It shows the title Number Enums and two black boxes. On clicking: 1 - It shows the default usage, // The items are represented internally by numbers starting at 0 enum WeatherType { Sunny, Cloudy, Rainy, Storm, Frost, Nightly } 2- It shows the other usage for numbers where we can set numbers without letting TypeScript to guess. enum WeatherType { Sunny = 1, Cloudy = 2, Rainy = 3, Storm = 4, Frost = 5, Nightly = 6 } 3- Navigates to Number Enums - Usage slide where we see the title and a black box. https://www.typescriptlang.org/play/index.html Use it to show some examples.
  • #27: It shows the title Number Enums - Usage and a black box. On clicking: 1- it shows the code to return an icon type using the Enumeration. class Weather { getWeatherIcon(weatherType: WeatherType) { switch (weatherType) { case WeatherType.Sunny: return 'weather_sunny'; case WeatherType.Cloudy: return 'weather_cloudy'; case WeatherType.Rainy: return 'weather_rain'; case WeatherType.Storm: return 'weather_storm'; case WeatherType.Frost: return 'weather_frost'; case WeatherType.Nightly: return 'weather_nightly'; } } } 2- Navigates to the next slide String Enums https://www.typescriptlang.org/play/index.html Use it to show some examples.
  • #28: In this slide it shows the title String Enums and a black box. On clicking: 1- It shows the code: class Weather { getWeatherIcon(weatherType: WeatherType) { switch (weatherType) { case WeatherType.Sunny: return 'weather_sunny'; case WeatherType.Cloudy: return 'weather_cloudy'; case WeatherType.Rainy: return 'weather_rain'; case WeatherType.Storm: return 'weather_storm'; case WeatherType.Frost: return 'weather_frost'; case WeatherType.Nightly: return 'weather_nightly'; } } } 2- It navigates to Functions Slide Explain that using this makes unnecessary the previous slide. https://basarat.gitbooks.io/typescript/content/docs/enums.html https://www.typescriptlang.org/play/index.html Use it to show some examples.
  • #29: It shows a Functions title and two subtitles (Function Types, Overloading) On clicking it navigates to Function Types 1/3