SlideShare ist ein Scribd-Unternehmen logo
1 von 17
© 2016, Right IT Services. All rights reserved
TypeScript
Friday, 02 December 2016
2
What’s TypeScript?
TypeScript
First appered 2012
Free and OpenSource project by Microsoft
Created by the father of C# Anders Hejlsberg
Typed superset of JavaScript
A new language that compiles to plain JavaScript
ES3 - ES5, ES6
2009
3
Friends - Who’s Using TypeScript?
TypeScript
4
Why TypeScript?
TypeScript
JavaScript
SUCKS!
5
Why TypeScript?
JS is interpreted, not compiled
There are no design-time intellisense or compile-time assistance to help you point out errors
A function is your contract with your caller
Function with parameters are more like guidelines
Global Scope
Why is the method called includes and not contains in Array?
MooTools adds this method to Array.prototype.
Scope
TypeScript
function func(anyvar) {
console.log(arguments.length);
return anyvar+ 1;
}
func();
func(“Change to TypeScript");
func("Change to", "TypeScript");
func(function(){});
f(1,2,3,4,5); //5
var foo = 1;
function test1() { foo = 2; console.log(foo); };
test1(); console.log(foo);
var foo = 3;
function test2() { var foo = 4; console.log(foo); };
test2(); console.log(foo);
6
Why TypeScript?
Object extension
Object inheritance is possible, but too messy
Some pitfalls
TypeScript
var a = "2";
var b = "2";
var c = a * b; //4
var a = "a";
var b = "b";
var c = a * b; //NaN
console.log('4' - 4);
console.log('4' + 4);
//0
//44
undefined == undefined //true
null == undefined //true
null === undefined //false
0 == undefined //false
”” == undefined //false
false == undefined //false
false == 0 //true
false == ”” //true
void 0
var x = { a : 1, b : 2 }
x.c = 3;
console.log(x[“a”] + x.b + x.c);
7
Features of TypeScript
Namespaces & Modules
Nomenclature has changed
Align with ECMAScript 2015
TypeScript
namespace Animal {
export namespace Domestic {
export function move(distance: number): boolean {
}
}
}
var moved = Animal.Domestic.move(100);
8
Features of TypeScript
Interfaces
TypeScript
enum Direction{
Right = 0,
Left = 1
}
interface Animal {
name: string;
age: number;
domestic: boolean;
}
interface Animal {
move(distance: number, direction: Direction);
}
export class Cat implements Animal{
...
}
9
TypeScript Features
Abstract & Classes
TypeScript
abstract class Animal {
abstract getName(): string;
}
class Cat extends Animal {
constructor() {
super();
}
public getName(): string {
return "";
}
}
class Dog extends Animal {
constructor() {
super();
}
getName(): string {
return "";
}
}
class Kennel<T extends Animal> {
getName<T extends Animal>(animal: T) : string {
return animal.getName();
}
}
var cat = new Cat();
var dog: Dog = new Dog();
var kennel = new Kennel();
var animal1 = kennel.getName(cat);
var animal2 = kennel.getName(dog);
10
TypeScript Features
Variable Scoping
TypeScript
for (var i = 0; i < this.length; i++) {
…
}
for (var i = 0; i < this.length; i++) { //Error
…
}
if(this.length > 0) {
let self = this[1]; //scoped only to if conditional
}
11
TypeScript Features
Declaration Files
.d.ts files containing declarative statements to describe TypeScript modules, classes, objects, etc.
Definition files for common JavaScript libraries makes them very easy to work with, and provides strong type checking
TypeScript
12
TypeScript Declaration Files
Variable Scoping
TypeScript
for (var i = 0; i < this.length; i++) {
…
}
for (var i = 0; i < this.length; i++) { //Error
…
}
if(this.length > 0) {
let self = this[1]; //scoped only to if conditional
}
13
Problems TypeScript Solves
Type safety
All the features are optionals
We can not use types
All valid JavaScript is valid TypeScript
Modules
TypeScript
module outer {
var str = "hello world";
}
var outer;
(function (outer) {
var str = "hello world";
})(outer || (outer = {}));
14
Problems TypeScript Solves
Checks Types
Less Runtime Bugs
Less Unit Tests
assert.isString
assert.isNumber
TypeScript
15
Problems TypeScript Doesn’t Solve
Mistakes
Logical mistakes
Lack of knowledge
Still need to understand JS
TS without knowing JS == disaster
what output will TS provide?
Won't make it faster
Won't make you code faster
Won't make app run faster
The any type
Stands for NO TYPE
Very easy and tempting to use
Will spoil your app if used in big amounts
Debug
browsers don't execute TS
source and output: different
TypeScript
16
Conclusion
TypeScript
WHEN YOU HAVE TO DO IT, DO IT RIGHT
© 2016, Right IT Services. All rights reserved Rua Odette Saint Maurice Lote 3B | Edifício L | Escritório A | Piso -1 | 1700-097 Lisboa | Portugal | +351 218 232 261
Pedro Azevedo – Technical Lead Dynamics CRM
Environment Microsoft Dynamics CRM
Friday, 02 December 2016
TypeScript

Weitere ähnliche Inhalte

Was ist angesagt?

Novidades Do Asp.Net 4 E Do Visual Studio 2010
Novidades Do Asp.Net 4 E Do Visual Studio 2010Novidades Do Asp.Net 4 E Do Visual Studio 2010
Novidades Do Asp.Net 4 E Do Visual Studio 2010
Rodrigo Kono
 

Was ist angesagt? (19)

Lightning strikes twice- SEDreamin
Lightning strikes twice- SEDreaminLightning strikes twice- SEDreamin
Lightning strikes twice- SEDreamin
 
Hands-On Workshop: Introduction to Coding for on Force.com for Admins and Non...
Hands-On Workshop: Introduction to Coding for on Force.com for Admins and Non...Hands-On Workshop: Introduction to Coding for on Force.com for Admins and Non...
Hands-On Workshop: Introduction to Coding for on Force.com for Admins and Non...
 
Salesforce Coding techniques that keep your admins happy (DF13)
Salesforce Coding techniques that keep your admins happy (DF13)Salesforce Coding techniques that keep your admins happy (DF13)
Salesforce Coding techniques that keep your admins happy (DF13)
 
Salesforce lightning design system
Salesforce lightning design systemSalesforce lightning design system
Salesforce lightning design system
 
Lightning overview
Lightning overviewLightning overview
Lightning overview
 
How to tdd your mvp
How to tdd your mvpHow to tdd your mvp
How to tdd your mvp
 
Force.com Friday - Intro to Visualforce
Force.com Friday - Intro to VisualforceForce.com Friday - Intro to Visualforce
Force.com Friday - Intro to Visualforce
 
Discover Salesforce Lightning 1
Discover Salesforce Lightning 1Discover Salesforce Lightning 1
Discover Salesforce Lightning 1
 
Salesforce Super Slider Lightning Component ppt
Salesforce Super Slider Lightning Component pptSalesforce Super Slider Lightning Component ppt
Salesforce Super Slider Lightning Component ppt
 
2014 SharePoint Saturday Melbourne Apps or not to Apps
2014 SharePoint Saturday Melbourne Apps or not to Apps2014 SharePoint Saturday Melbourne Apps or not to Apps
2014 SharePoint Saturday Melbourne Apps or not to Apps
 
Forge UI: A New Way to Customize the Atlassian User Experience
Forge UI: A New Way to Customize the Atlassian User ExperienceForge UI: A New Way to Customize the Atlassian User Experience
Forge UI: A New Way to Customize the Atlassian User Experience
 
Lighnting component development
Lighnting component developmentLighnting component development
Lighnting component development
 
Novidades Do Asp.Net 4 E Do Visual Studio 2010
Novidades Do Asp.Net 4 E Do Visual Studio 2010Novidades Do Asp.Net 4 E Do Visual Studio 2010
Novidades Do Asp.Net 4 E Do Visual Studio 2010
 
Lightning Components Workshop v2
Lightning Components Workshop v2Lightning Components Workshop v2
Lightning Components Workshop v2
 
How DotNet, SharePoint, and Azure helps to build a Custom Web Application wi...
 How DotNet, SharePoint, and Azure helps to build a Custom Web Application wi... How DotNet, SharePoint, and Azure helps to build a Custom Web Application wi...
How DotNet, SharePoint, and Azure helps to build a Custom Web Application wi...
 
DF2UFL 2012: Developer's Den - What's New and What's on the Horizon
DF2UFL 2012: Developer's Den - What's New and What's on the HorizonDF2UFL 2012: Developer's Den - What's New and What's on the Horizon
DF2UFL 2012: Developer's Den - What's New and What's on the Horizon
 
Go Faster with Lightning - Overview
Go Faster with Lightning - OverviewGo Faster with Lightning - Overview
Go Faster with Lightning - Overview
 
Updates on the Data Center Apps Program
Updates on the Data Center Apps ProgramUpdates on the Data Center Apps Program
Updates on the Data Center Apps Program
 
Powerapps & Flow
Powerapps & FlowPowerapps & Flow
Powerapps & Flow
 

Andere mochten auch

Single-Page Web Application Architecture
Single-Page Web Application ArchitectureSingle-Page Web Application Architecture
Single-Page Web Application Architecture
Eray Arslan
 

Andere mochten auch (20)

Rits Brown Bag - Office 365
Rits Brown Bag - Office 365Rits Brown Bag - Office 365
Rits Brown Bag - Office 365
 
Rits Brown Bag - Extending and Integrating in Microsoft Dynamics CRM
Rits Brown Bag - Extending and Integrating in Microsoft Dynamics CRMRits Brown Bag - Extending and Integrating in Microsoft Dynamics CRM
Rits Brown Bag - Extending and Integrating in Microsoft Dynamics CRM
 
Rits Brown Bag - PHP & PHPMyAdmin
Rits Brown Bag - PHP & PHPMyAdminRits Brown Bag - PHP & PHPMyAdmin
Rits Brown Bag - PHP & PHPMyAdmin
 
single page application
single page applicationsingle page application
single page application
 
Angular 2 with TypeScript
Angular 2 with TypeScriptAngular 2 with TypeScript
Angular 2 with TypeScript
 
The Tale of 2 CLIs - Ember-cli and Angular-cli
The Tale of 2 CLIs - Ember-cli and Angular-cliThe Tale of 2 CLIs - Ember-cli and Angular-cli
The Tale of 2 CLIs - Ember-cli and Angular-cli
 
Single-Page Web Application Architecture
Single-Page Web Application ArchitectureSingle-Page Web Application Architecture
Single-Page Web Application Architecture
 
Angular 2 + TypeScript = true. Let's Play!
Angular 2 + TypeScript = true. Let's Play!Angular 2 + TypeScript = true. Let's Play!
Angular 2 + TypeScript = true. Let's Play!
 
Using Angular-CLI to Deploy an Angular 2 App Using Firebase in 30 Minutes
Using Angular-CLI to Deploy an Angular 2 App Using Firebase in 30 MinutesUsing Angular-CLI to Deploy an Angular 2 App Using Firebase in 30 Minutes
Using Angular-CLI to Deploy an Angular 2 App Using Firebase in 30 Minutes
 
Angular 2 with TypeScript
Angular 2 with TypeScriptAngular 2 with TypeScript
Angular 2 with TypeScript
 
Creating an Angular 2 Angular CLI app in 15 Minutes Using MaterializeCSS & Fi...
Creating an Angular 2 Angular CLI app in 15 Minutes Using MaterializeCSS & Fi...Creating an Angular 2 Angular CLI app in 15 Minutes Using MaterializeCSS & Fi...
Creating an Angular 2 Angular CLI app in 15 Minutes Using MaterializeCSS & Fi...
 
Single page application
Single page applicationSingle page application
Single page application
 
Single page application
Single page applicationSingle page application
Single page application
 
Angular 1.x vs 2 - In code level
Angular 1.x vs 2 - In code levelAngular 1.x vs 2 - In code level
Angular 1.x vs 2 - In code level
 
Getting started with Angular CLI
Getting started with Angular CLIGetting started with Angular CLI
Getting started with Angular CLI
 
02 Node introduction
02 Node introduction02 Node introduction
02 Node introduction
 
Getting Started with the Angular 2 CLI
Getting Started with the Angular 2 CLIGetting Started with the Angular 2 CLI
Getting Started with the Angular 2 CLI
 
Node js for beginners
Node js for beginnersNode js for beginners
Node js for beginners
 
Node js introduction
Node js introductionNode js introduction
Node js introduction
 
An afternoon with angular 2
An afternoon with angular 2An afternoon with angular 2
An afternoon with angular 2
 

Ähnlich wie Rits Brown Bag - TypeScript

JSLounge - TypeScript 소개
JSLounge - TypeScript 소개JSLounge - TypeScript 소개
JSLounge - TypeScript 소개
Reagan Hwang
 
A well-typed program never goes wrong
A well-typed program never goes wrongA well-typed program never goes wrong
A well-typed program never goes wrong
Julien Wetterwald
 

Ähnlich wie Rits Brown Bag - TypeScript (20)

Getting started with typescript
Getting started with typescriptGetting started with typescript
Getting started with typescript
 
TypeScript Presentation - Jason Haffey
TypeScript Presentation - Jason HaffeyTypeScript Presentation - Jason Haffey
TypeScript Presentation - Jason Haffey
 
Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Tdd is not about testing (OOP)
Tdd is not about testing (OOP)
 
Einführung in TypeScript
Einführung in TypeScriptEinführung in TypeScript
Einführung in TypeScript
 
Building End-to-End Apps Using Typescript
Building End-to-End Apps Using TypescriptBuilding End-to-End Apps Using Typescript
Building End-to-End Apps Using Typescript
 
Ecmascript 2015 – best of new features()
Ecmascript 2015 – best of new features()Ecmascript 2015 – best of new features()
Ecmascript 2015 – best of new features()
 
JSLounge - TypeScript 소개
JSLounge - TypeScript 소개JSLounge - TypeScript 소개
JSLounge - TypeScript 소개
 
Building End to-End Web Apps Using TypeScript
Building End to-End Web Apps Using TypeScriptBuilding End to-End Web Apps Using TypeScript
Building End to-End Web Apps Using TypeScript
 
Typescript language extension of java script
Typescript language extension of java scriptTypescript language extension of java script
Typescript language extension of java script
 
A la découverte de TypeScript
A la découverte de TypeScriptA la découverte de TypeScript
A la découverte de TypeScript
 
L04 Software Design Examples
L04 Software Design ExamplesL04 Software Design Examples
L04 Software Design Examples
 
Practical TypeScript
Practical TypeScriptPractical TypeScript
Practical TypeScript
 
Typescript barcelona
Typescript barcelonaTypescript barcelona
Typescript barcelona
 
"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues
 
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
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testing
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
 
A well-typed program never goes wrong
A well-typed program never goes wrongA well-typed program never goes wrong
A well-typed program never goes wrong
 
Who killed object oriented design?
Who killed object oriented design?Who killed object oriented design?
Who killed object oriented design?
 
Intro to Javascript
Intro to JavascriptIntro to Javascript
Intro to Javascript
 

Mehr von Right IT Services

Mehr von Right IT Services (15)

Rits Brown Bag - React Native and Salesforce
Rits Brown Bag - React Native and SalesforceRits Brown Bag - React Native and Salesforce
Rits Brown Bag - React Native and Salesforce
 
Rits Brown Bag - Conga Composer
Rits Brown Bag - Conga ComposerRits Brown Bag - Conga Composer
Rits Brown Bag - Conga Composer
 
Rits Brown Bag - Environment MS Dynamics CRM
Rits Brown Bag -  Environment MS Dynamics CRMRits Brown Bag -  Environment MS Dynamics CRM
Rits Brown Bag - Environment MS Dynamics CRM
 
Rits Brown Bag - Google AdWords Basics
Rits Brown Bag - Google AdWords BasicsRits Brown Bag - Google AdWords Basics
Rits Brown Bag - Google AdWords Basics
 
Salesforce.com Continuous Integration
Salesforce.com Continuous IntegrationSalesforce.com Continuous Integration
Salesforce.com Continuous Integration
 
Rits Brown Bag - SharePoint 2016
Rits Brown Bag - SharePoint 2016Rits Brown Bag - SharePoint 2016
Rits Brown Bag - SharePoint 2016
 
Rits Brown Bag - vtiger
Rits Brown Bag - vtigerRits Brown Bag - vtiger
Rits Brown Bag - vtiger
 
Rits Brown Bag - Salesforce Social Studio
Rits Brown Bag - Salesforce Social StudioRits Brown Bag - Salesforce Social Studio
Rits Brown Bag - Salesforce Social Studio
 
Rits Brown Bag - Introduction to SharePoint
Rits Brown Bag - Introduction to SharePointRits Brown Bag - Introduction to SharePoint
Rits Brown Bag - Introduction to SharePoint
 
Workbook for Lightning Developers
Workbook for Lightning DevelopersWorkbook for Lightning Developers
Workbook for Lightning Developers
 
Rits Brown Bag - Surveys and Polls Techniques
Rits Brown Bag - Surveys and Polls TechniquesRits Brown Bag - Surveys and Polls Techniques
Rits Brown Bag - Surveys and Polls Techniques
 
Rits Brown Bag - Salesforce Lightning External Connection
Rits Brown Bag - Salesforce Lightning External ConnectionRits Brown Bag - Salesforce Lightning External Connection
Rits Brown Bag - Salesforce Lightning External Connection
 
Rits Brown Bag - Anatomy of a Mobile App
Rits Brown Bag - Anatomy of a Mobile AppRits Brown Bag - Anatomy of a Mobile App
Rits Brown Bag - Anatomy of a Mobile App
 
Rits Brown Bag - Salesforce Duplicate Management
Rits Brown Bag - Salesforce Duplicate ManagementRits Brown Bag - Salesforce Duplicate Management
Rits Brown Bag - Salesforce Duplicate Management
 
Rits Brown Bag - Salesforce AppExchange
Rits Brown Bag - Salesforce AppExchangeRits Brown Bag - Salesforce AppExchange
Rits Brown Bag - Salesforce AppExchange
 

Kürzlich hochgeladen

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Kürzlich hochgeladen (20)

Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 

Rits Brown Bag - TypeScript

  • 1. © 2016, Right IT Services. All rights reserved TypeScript Friday, 02 December 2016
  • 2. 2 What’s TypeScript? TypeScript First appered 2012 Free and OpenSource project by Microsoft Created by the father of C# Anders Hejlsberg Typed superset of JavaScript A new language that compiles to plain JavaScript ES3 - ES5, ES6 2009
  • 3. 3 Friends - Who’s Using TypeScript? TypeScript
  • 5. 5 Why TypeScript? JS is interpreted, not compiled There are no design-time intellisense or compile-time assistance to help you point out errors A function is your contract with your caller Function with parameters are more like guidelines Global Scope Why is the method called includes and not contains in Array? MooTools adds this method to Array.prototype. Scope TypeScript function func(anyvar) { console.log(arguments.length); return anyvar+ 1; } func(); func(“Change to TypeScript"); func("Change to", "TypeScript"); func(function(){}); f(1,2,3,4,5); //5 var foo = 1; function test1() { foo = 2; console.log(foo); }; test1(); console.log(foo); var foo = 3; function test2() { var foo = 4; console.log(foo); }; test2(); console.log(foo);
  • 6. 6 Why TypeScript? Object extension Object inheritance is possible, but too messy Some pitfalls TypeScript var a = "2"; var b = "2"; var c = a * b; //4 var a = "a"; var b = "b"; var c = a * b; //NaN console.log('4' - 4); console.log('4' + 4); //0 //44 undefined == undefined //true null == undefined //true null === undefined //false 0 == undefined //false ”” == undefined //false false == undefined //false false == 0 //true false == ”” //true void 0 var x = { a : 1, b : 2 } x.c = 3; console.log(x[“a”] + x.b + x.c);
  • 7. 7 Features of TypeScript Namespaces & Modules Nomenclature has changed Align with ECMAScript 2015 TypeScript namespace Animal { export namespace Domestic { export function move(distance: number): boolean { } } } var moved = Animal.Domestic.move(100);
  • 8. 8 Features of TypeScript Interfaces TypeScript enum Direction{ Right = 0, Left = 1 } interface Animal { name: string; age: number; domestic: boolean; } interface Animal { move(distance: number, direction: Direction); } export class Cat implements Animal{ ... }
  • 9. 9 TypeScript Features Abstract & Classes TypeScript abstract class Animal { abstract getName(): string; } class Cat extends Animal { constructor() { super(); } public getName(): string { return ""; } } class Dog extends Animal { constructor() { super(); } getName(): string { return ""; } } class Kennel<T extends Animal> { getName<T extends Animal>(animal: T) : string { return animal.getName(); } } var cat = new Cat(); var dog: Dog = new Dog(); var kennel = new Kennel(); var animal1 = kennel.getName(cat); var animal2 = kennel.getName(dog);
  • 10. 10 TypeScript Features Variable Scoping TypeScript for (var i = 0; i < this.length; i++) { … } for (var i = 0; i < this.length; i++) { //Error … } if(this.length > 0) { let self = this[1]; //scoped only to if conditional }
  • 11. 11 TypeScript Features Declaration Files .d.ts files containing declarative statements to describe TypeScript modules, classes, objects, etc. Definition files for common JavaScript libraries makes them very easy to work with, and provides strong type checking TypeScript
  • 12. 12 TypeScript Declaration Files Variable Scoping TypeScript for (var i = 0; i < this.length; i++) { … } for (var i = 0; i < this.length; i++) { //Error … } if(this.length > 0) { let self = this[1]; //scoped only to if conditional }
  • 13. 13 Problems TypeScript Solves Type safety All the features are optionals We can not use types All valid JavaScript is valid TypeScript Modules TypeScript module outer { var str = "hello world"; } var outer; (function (outer) { var str = "hello world"; })(outer || (outer = {}));
  • 14. 14 Problems TypeScript Solves Checks Types Less Runtime Bugs Less Unit Tests assert.isString assert.isNumber TypeScript
  • 15. 15 Problems TypeScript Doesn’t Solve Mistakes Logical mistakes Lack of knowledge Still need to understand JS TS without knowing JS == disaster what output will TS provide? Won't make it faster Won't make you code faster Won't make app run faster The any type Stands for NO TYPE Very easy and tempting to use Will spoil your app if used in big amounts Debug browsers don't execute TS source and output: different TypeScript
  • 17. WHEN YOU HAVE TO DO IT, DO IT RIGHT © 2016, Right IT Services. All rights reserved Rua Odette Saint Maurice Lote 3B | Edifício L | Escritório A | Piso -1 | 1700-097 Lisboa | Portugal | +351 218 232 261 Pedro Azevedo – Technical Lead Dynamics CRM Environment Microsoft Dynamics CRM Friday, 02 December 2016 TypeScript