SlideShare a Scribd company logo
TypeScript
and why it's so awesome !!!
by polishdeveloper
Agenda
a bit about myself
getting started with TS
types and generics
classes and inheritance
DefinitelyTyped
real code example
pros and cons
other projects like TS
A bit about me

Hides under PolishDeveloper nick

Software dev for over 8yr

Reads CleanCoding for good sleep

Loves car racing, drifter for 3yr

When no one is looking plays minecraft
Another language – why ?

Slow shift to frontend

JS codebase gets bigger everyday

OO is very popular

JS getting more complex

Prototyping is like battleaxe

Everyone wants to write JS

There is ES6 already
Story time
Look, I've found a typed Javascript
Getting there

Strict superset of Javascript

First public version in October 2012

Created by Anders Hejlsberg

It's a transpiler

Types,Generics,Classes,Modules,Interfaces o/
Lets see some code
Ready ?
Types
enum MessageTypes {'New', 'Read', 'Archived'};
var message: string|string[] = 'abc',
count: number = 123,
isAvailable: boolean = false,
recipientIds: Array<number> = [10, 11, 12],
type:MessageTypes = MessageTypes.New,
tmp:any;
Functions
function triggerError(message:string):void {
alert('Error ' + message);
}
function square(value:number):number {
return value*value;
}
Interfaces
interface LabelledValue {
label: string;
}
function printLabel(labelledObj: LabelledValue) {
console.log(labelledObj.label);
}
var myObj = <LabelledValue>{};
var myObj = {size: 10, label: "Size 10 Object"};
printLabel(myObj);
Function types
interface SearchFunc {
(source: string, subString: string): boolean;
}
var mySearch: SearchFunc;
mySearch = function(source: string, subString: string) {
var result = source.search(subString);
return result == -1 ? false : true;
};
Extending interfaces
interface Shape {
color: string;
}
interface PenStroke {
penWidth: number;
}
interface Square extends Shape, PenStroke {
sideLength: number;
}
var square = <Square>{
color: 'blue',
sideLength: 10,
penWidth: 5.0
};
Optional properties
interface MyObject {
name: string;
size?: number;
}
function printMyObject(object:MyObject) {
var msg:string = 'Element ' + object.name;
if (object.size)
msg += '(' + object.size + ')';
console.log(msg);
}
var sofa = {name:'sofa'};
printMyObject(sofa);
Classes
class Greeter {
greeting: string;
constructor(message: string) {
this.greeting = message;
}
greet() {
return "Hello, " + this.greeting;
}
}
var greeter = new Greeter("world");
Extending classes
class Animal {
private name:string;
constructor(x:Person);
constructor(n: string) { this.name = n; }
}
class Rhino extends Animal {
constructor() { super("Rhino"); }
}
class Employee {
private firstname:string;
constructor(n: string) { this.name = n; }
}
var animal:Animal = new Animal("Kiwi");
var rhino = new Rhino();
var employee = new Employee("Bob");
Classes cdn
var animal:Animal = new Animal("Kiwi");
var rhino = new Rhino();
var employee = new Employee("Bob");
animal = rhino;
animal = employee; //fail
Mixins
class Disposable {
isDisposed: boolean;
dispose() { this.isDisposed = true; }
}
class Activatable {
isActive: boolean;
activate() { this.isActive = true; }
deactivate() { this.isActive = false; }
}
class MyObject implements Disposable, Activatable {
...
}
var x = new MyObject();
x.activate();
Some Extras
function log(message:string, ...args:string[]) {
console.log(message, args);
}
setTimeout(()=>{console.log('hello');}, 500);
callback(seconds=>{
console.log('done in ' + seconds + 's')
});
DefinitelyTyped
npm install tsd -g
tsd query angular
tsd install mocha –save
in app point to it :
/// <reference path='typing/tsd.d.ts' />
Lets see some real code
Ready ?
Boundary interface
export interface IGetMeterpointStructureResponse {
id: number;
identifier: string;
type: string;
supplyStartDate: Date;
meters: Array<IMeter>;
isEconomy7: boolean;
supplyAddress: IAddress;
}
Service with promise
getMeterPoints(account: Project.IAccount)
:ng.IPromise<Project.IGetMeterpointsResponse> {
var deferred = this.$q.defer(),
link = this.config.getAPILink('id', {id: account.id});
this.$http.get(link).success(function(response){
deferred.resolve(response);
}).error(function(reason:Error) {
deferred.reject(new Error(reason.message));
});
return deferred.promise;
}
Stats directive
export class StatsOn implements ng.IDirective {
public restrict: string = 'A';
public replace: boolean = false;
public link: (s: ng.IScope, e: ng.IAugmentedJQuery, a: ng.IAttributes) => void;
constructor(statsService:StatsService) {
StatsOn.prototype.link = (scope: ng.IScope, element: ng.IAugmentedJQuery, attrs: ng.IAttributes) => {
if (typeof attrs['statsOn'] == 'undefined')
return;
element.on(attrs['statsOn'], function () {
var statName = attrs['statsEvent'];
if (statName == false)
statName = 'User '+attrs['statsOn']+'ed on "'+element.text() + '"';
var data = ...;
statsService.track(statName, data);
});
};
}
public static Factory(): ng.IDirectiveFactory {
var directive: ng.IDirectiveFactory =
(ss:StatsService) => new StatsOn(ss);
directive['$inject'] = ['StatsService'];
return directive;
}
}
Provider
export class UUIDProvider implements ng.IServiceProvider
{
private EXPIRATION = 7200000; //lets do two hours
private FORMAT = 'xxxxxxxx-xxxx-4xxx-yxxx';
private storage:IUUIDStorage;
private uuid:string;
// Provider's factory function
public $get($cookies) : IUUIDService {
this.uuid = this.warmup($cookies);
return {
get: () => { return this.uuid; },
prolong: () => { this.storage.set(this.uuid, this.calculateExpiration(new Date())); }
};
...
}
Controller
export class ErrorModalController {
public static $inject:Array<string> = ['$rootScope'];
constructor(private $rootScope:IRootScope) {
$rootScope.errorModal = {
visible: false,
message: null
};
$rootScope.throwError = function(message:string) {
$rootScope.errorModal.visible = true;
$rootScope.errorModal.message = message;
};
}
}
Why not ES6 ?
It's still dynamically typed...
Not supported in old browsers (Babel ?)
ES5 – Dec 2009
ES6 – June 2015
ES7 - ???
TS1.4 – January 2014
TS1.5 – July 2015
TS1.6 – Sept 2015
TS1.7 - ???
Pros&Cons

Works everywhere

Static Typing (if you like it)

Defensive programming

Real OO approach

Much easier to write UnitTests

Autocomplete in supported IDEs

Learning curve

Extra compilation stage

Requires bindings – Sometimes you have to write your
Other projects like TS

ATScript

Flow

JSX

Dart
Resources
http://www.typescriptlang.org/Handbook
http://definitelytyped.org/
Q/A
Questions ???
Hugs time
Thank you!
o/
Twitter:polishdeveloper
Skype:polishdeveloper
GitHub:polishdeveloper

More Related Content

PDF
San Francisco Java User Group
PDF
はじめてのMongoDB
PDF
From mysql to MongoDB(MongoDB2011北京交流会)
PDF
20110514 mongo dbチューニング
PDF
Embedding a language into string interpolator
PDF
DEF CON 23 - amit ashbel and maty siman - game of hacks
PDF
Inside MongoDB: the Internals of an Open-Source Database
KEY
CouchDB on Android
San Francisco Java User Group
はじめてのMongoDB
From mysql to MongoDB(MongoDB2011北京交流会)
20110514 mongo dbチューニング
Embedding a language into string interpolator
DEF CON 23 - amit ashbel and maty siman - game of hacks
Inside MongoDB: the Internals of an Open-Source Database
CouchDB on Android

What's hot (20)

KEY
MongoDB
PDF
Indexing
PDF
The art of readable code (ch1~ch4)
PDF
MongoDB Performance Debugging
PDF
The State of NoSQL
ODP
Introduction to Domain-Driven Design
PDF
(gentle (introduction Clojure))
PDF
Becoming a Pythonist
PDF
Opa presentation at GamesJs
DOCX
Java and xml
PDF
NoSQL を Ruby で実践するための n 個の方法
KEY
DashProfiler 200807
PDF
Groovy.pptx
PDF
Automatically Spotting Cross-language Relations
PPTX
Mongo db modifiers
ODP
Contando uma história com O.O.
PPTX
Moose Best Practices
PDF
Natural Language Toolkit (NLTK), Basics
PDF
Map/Confused? A practical approach to Map/Reduce with MongoDB
PDF
Perl object ?
MongoDB
Indexing
The art of readable code (ch1~ch4)
MongoDB Performance Debugging
The State of NoSQL
Introduction to Domain-Driven Design
(gentle (introduction Clojure))
Becoming a Pythonist
Opa presentation at GamesJs
Java and xml
NoSQL を Ruby で実践するための n 個の方法
DashProfiler 200807
Groovy.pptx
Automatically Spotting Cross-language Relations
Mongo db modifiers
Contando uma história com O.O.
Moose Best Practices
Natural Language Toolkit (NLTK), Basics
Map/Confused? A practical approach to Map/Reduce with MongoDB
Perl object ?
Ad

Viewers also liked (12)

PPTX
Good practices for Developers
PPTX
Typescript - Object Oriented Approach in JS
PDF
MicroMedics Presentation
PPT
Sps presentation to ppd & school
PPTX
Question 3
PDF
Image processing
DOC
Cuti umum dan cuti sekolah 2015
PDF
Box jellyfish
PDF
Mobilemonday atlanta-2015
PDF
5 s program
PDF
Data-Driven Product Innovation
PPTX
Miley Cyrus Case Study
Good practices for Developers
Typescript - Object Oriented Approach in JS
MicroMedics Presentation
Sps presentation to ppd & school
Question 3
Image processing
Cuti umum dan cuti sekolah 2015
Box jellyfish
Mobilemonday atlanta-2015
5 s program
Data-Driven Product Innovation
Miley Cyrus Case Study
Ad

Similar to Typescript - why it's awesome (20)

PPTX
Typescript - A developer friendly javascript
PPTX
TypeScript by Howard
PPTX
Howard type script
PPTX
Type script by Howard
PPTX
Typescript barcelona
PDF
TypeScript Introduction
PDF
Introduction to typescript
PPTX
Introduction to TypeScript
PPTX
Complete Notes on Angular 2 and TypeScript
PPTX
Why TypeScript?
PDF
Back to the Future with TypeScript
PPTX
Academy PRO: ES2015
PDF
TypeScript for Java Developers
PDF
Js objects
PDF
Steam Learn: Javascript and OOP
PDF
Introduction to TypeScript
PDF
Typescript is the best by Maxim Kryuk
PDF
Typescript is the best
PPTX
TypeScript - Silver Bullet for the Full-stack Developers
PDF
運用Closure Compiler 打造高品質的JavaScript
Typescript - A developer friendly javascript
TypeScript by Howard
Howard type script
Type script by Howard
Typescript barcelona
TypeScript Introduction
Introduction to typescript
Introduction to TypeScript
Complete Notes on Angular 2 and TypeScript
Why TypeScript?
Back to the Future with TypeScript
Academy PRO: ES2015
TypeScript for Java Developers
Js objects
Steam Learn: Javascript and OOP
Introduction to TypeScript
Typescript is the best by Maxim Kryuk
Typescript is the best
TypeScript - Silver Bullet for the Full-stack Developers
運用Closure Compiler 打造高品質的JavaScript

Recently uploaded (20)

PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
assetexplorer- product-overview - presentation
PDF
Designing Intelligence for the Shop Floor.pdf
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Digital Systems & Binary Numbers (comprehensive )
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
medical staffing services at VALiNTRY
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
System and Network Administration Chapter 2
PDF
Understanding Forklifts - TECH EHS Solution
PPT
Introduction Database Management System for Course Database
PPTX
L1 - Introduction to python Backend.pptx
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
assetexplorer- product-overview - presentation
Designing Intelligence for the Shop Floor.pdf
How to Migrate SBCGlobal Email to Yahoo Easily
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Digital Systems & Binary Numbers (comprehensive )
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
CHAPTER 2 - PM Management and IT Context
Navsoft: AI-Powered Business Solutions & Custom Software Development
PTS Company Brochure 2025 (1).pdf.......
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
medical staffing services at VALiNTRY
Upgrade and Innovation Strategies for SAP ERP Customers
Design an Analysis of Algorithms II-SECS-1021-03
Softaken Excel to vCard Converter Software.pdf
System and Network Administration Chapter 2
Understanding Forklifts - TECH EHS Solution
Introduction Database Management System for Course Database
L1 - Introduction to python Backend.pptx

Typescript - why it's awesome

  • 1. TypeScript and why it's so awesome !!! by polishdeveloper
  • 2. Agenda a bit about myself getting started with TS types and generics classes and inheritance DefinitelyTyped real code example pros and cons other projects like TS
  • 3. A bit about me  Hides under PolishDeveloper nick  Software dev for over 8yr  Reads CleanCoding for good sleep  Loves car racing, drifter for 3yr  When no one is looking plays minecraft
  • 4. Another language – why ?  Slow shift to frontend  JS codebase gets bigger everyday  OO is very popular  JS getting more complex  Prototyping is like battleaxe  Everyone wants to write JS  There is ES6 already
  • 5. Story time Look, I've found a typed Javascript
  • 6. Getting there  Strict superset of Javascript  First public version in October 2012  Created by Anders Hejlsberg  It's a transpiler  Types,Generics,Classes,Modules,Interfaces o/
  • 7. Lets see some code Ready ?
  • 8. Types enum MessageTypes {'New', 'Read', 'Archived'}; var message: string|string[] = 'abc', count: number = 123, isAvailable: boolean = false, recipientIds: Array<number> = [10, 11, 12], type:MessageTypes = MessageTypes.New, tmp:any;
  • 9. Functions function triggerError(message:string):void { alert('Error ' + message); } function square(value:number):number { return value*value; }
  • 10. Interfaces interface LabelledValue { label: string; } function printLabel(labelledObj: LabelledValue) { console.log(labelledObj.label); } var myObj = <LabelledValue>{}; var myObj = {size: 10, label: "Size 10 Object"}; printLabel(myObj);
  • 11. Function types interface SearchFunc { (source: string, subString: string): boolean; } var mySearch: SearchFunc; mySearch = function(source: string, subString: string) { var result = source.search(subString); return result == -1 ? false : true; };
  • 12. Extending interfaces interface Shape { color: string; } interface PenStroke { penWidth: number; } interface Square extends Shape, PenStroke { sideLength: number; } var square = <Square>{ color: 'blue', sideLength: 10, penWidth: 5.0 };
  • 13. Optional properties interface MyObject { name: string; size?: number; } function printMyObject(object:MyObject) { var msg:string = 'Element ' + object.name; if (object.size) msg += '(' + object.size + ')'; console.log(msg); } var sofa = {name:'sofa'}; printMyObject(sofa);
  • 14. Classes class Greeter { greeting: string; constructor(message: string) { this.greeting = message; } greet() { return "Hello, " + this.greeting; } } var greeter = new Greeter("world");
  • 15. Extending classes class Animal { private name:string; constructor(x:Person); constructor(n: string) { this.name = n; } } class Rhino extends Animal { constructor() { super("Rhino"); } } class Employee { private firstname:string; constructor(n: string) { this.name = n; } } var animal:Animal = new Animal("Kiwi"); var rhino = new Rhino(); var employee = new Employee("Bob");
  • 16. Classes cdn var animal:Animal = new Animal("Kiwi"); var rhino = new Rhino(); var employee = new Employee("Bob"); animal = rhino; animal = employee; //fail
  • 17. Mixins class Disposable { isDisposed: boolean; dispose() { this.isDisposed = true; } } class Activatable { isActive: boolean; activate() { this.isActive = true; } deactivate() { this.isActive = false; } } class MyObject implements Disposable, Activatable { ... } var x = new MyObject(); x.activate();
  • 18. Some Extras function log(message:string, ...args:string[]) { console.log(message, args); } setTimeout(()=>{console.log('hello');}, 500); callback(seconds=>{ console.log('done in ' + seconds + 's') });
  • 19. DefinitelyTyped npm install tsd -g tsd query angular tsd install mocha –save in app point to it : /// <reference path='typing/tsd.d.ts' />
  • 20. Lets see some real code Ready ?
  • 21. Boundary interface export interface IGetMeterpointStructureResponse { id: number; identifier: string; type: string; supplyStartDate: Date; meters: Array<IMeter>; isEconomy7: boolean; supplyAddress: IAddress; }
  • 22. Service with promise getMeterPoints(account: Project.IAccount) :ng.IPromise<Project.IGetMeterpointsResponse> { var deferred = this.$q.defer(), link = this.config.getAPILink('id', {id: account.id}); this.$http.get(link).success(function(response){ deferred.resolve(response); }).error(function(reason:Error) { deferred.reject(new Error(reason.message)); }); return deferred.promise; }
  • 23. Stats directive export class StatsOn implements ng.IDirective { public restrict: string = 'A'; public replace: boolean = false; public link: (s: ng.IScope, e: ng.IAugmentedJQuery, a: ng.IAttributes) => void; constructor(statsService:StatsService) { StatsOn.prototype.link = (scope: ng.IScope, element: ng.IAugmentedJQuery, attrs: ng.IAttributes) => { if (typeof attrs['statsOn'] == 'undefined') return; element.on(attrs['statsOn'], function () { var statName = attrs['statsEvent']; if (statName == false) statName = 'User '+attrs['statsOn']+'ed on "'+element.text() + '"'; var data = ...; statsService.track(statName, data); }); }; } public static Factory(): ng.IDirectiveFactory { var directive: ng.IDirectiveFactory = (ss:StatsService) => new StatsOn(ss); directive['$inject'] = ['StatsService']; return directive; } }
  • 24. Provider export class UUIDProvider implements ng.IServiceProvider { private EXPIRATION = 7200000; //lets do two hours private FORMAT = 'xxxxxxxx-xxxx-4xxx-yxxx'; private storage:IUUIDStorage; private uuid:string; // Provider's factory function public $get($cookies) : IUUIDService { this.uuid = this.warmup($cookies); return { get: () => { return this.uuid; }, prolong: () => { this.storage.set(this.uuid, this.calculateExpiration(new Date())); } }; ... }
  • 25. Controller export class ErrorModalController { public static $inject:Array<string> = ['$rootScope']; constructor(private $rootScope:IRootScope) { $rootScope.errorModal = { visible: false, message: null }; $rootScope.throwError = function(message:string) { $rootScope.errorModal.visible = true; $rootScope.errorModal.message = message; }; } }
  • 26. Why not ES6 ? It's still dynamically typed... Not supported in old browsers (Babel ?) ES5 – Dec 2009 ES6 – June 2015 ES7 - ??? TS1.4 – January 2014 TS1.5 – July 2015 TS1.6 – Sept 2015 TS1.7 - ???
  • 27. Pros&Cons  Works everywhere  Static Typing (if you like it)  Defensive programming  Real OO approach  Much easier to write UnitTests  Autocomplete in supported IDEs  Learning curve  Extra compilation stage  Requires bindings – Sometimes you have to write your
  • 28. Other projects like TS  ATScript  Flow  JSX  Dart

Editor's Notes

  • #5: Two headed axe
  • #6: Two headed axe
  • #7: lead architect of C# and creator of Delphi and TurboPascal TSC is written in TypeScript
  • #8: lead architect of C# and creator of Delphi and TurboPascal TSC is written in TypeScript
  • #21: lead architect of C# and creator of Delphi and TurboPascal TSC is written in TypeScript
  • #27: lead architect of C# and creator of Delphi and TurboPascal TSC is written in TypeScript
  • #28: lead architect of C# and creator of Delphi and TurboPascal TSC is written in TypeScript
  • #29: lead architect of C# and creator of Delphi and TurboPascal TSC is written in TypeScript