SlideShare uma empresa Scribd logo
1 de 48
Baixar para ler offline
WhyStaticTypeCheckingisBetter
@AndrewRota
JavaScript Engineer,
With JavaScript...anything is possible
@AndrewRota | #empirejs 2/48
Change all the types...
@AndrewRota | #empirejs
var x; // x starts undefined
typeof x === 'undefined'
x = 5;  // now it's is a number
typeof x === 'number'
x = 'five'; // now it's a string
typeof x === 'string'
x = true;  // now it's a boolean
typeof x === 'boolean'
x = {value: 'five'}; // now it's an object
typeof x === 'object'
JS
3/48
We have types, but they're not static.
(No type is known or declared at compile time)
@AndrewRota | #empirejs 4/48
7 Types in JavaScript
@AndrewRota | #empirejs
Boolean Number String Object
Symbol Null Undefined
5/48
Most code has type expectations
...we just don't always acknowledge it.
@AndrewRota | #empirejs
function add(arr) {
    var sum = 0;
    for (var i = 0; i < arr.length; i++) {
        sum += arr[i];
    }
    return sum;
}
add([2,3]); // returns 5 as expected
add(['foo', 'bar']);  // returns "0foobar" (expected?)
add(null);  // Throws exception: cannot read prop 'length' of null
JS
6/48
What to do?
@AndrewRota | #empirejs 7/48
Ad Hoc Runtime Checks
@AndrewRota | #empirejs
function add(arr) {
    if (!Array.isArray(arr)) return;
    var sum = 0;
    for (var i = 0; i < arr.length; i++) {
        if (typeof arr[i] !== 'number') return;
        sum += arr[i];
    }
    return sum;
}
JS
8/48
Ad Hoc Runtime Checks
@AndrewRota | #empirejs
function add(arr) {
    if (!Array.isArray(arr)) throw('not an array');
    var sum = 0;
    for (var i = 0; i < arr.length; i++) {
        if (typeof arr[i] !== 'number') throw('not a number');
        sum += arr[i];
    }
    return sum;
}
JS
9/48
Type Annotations
@AndrewRota | #empirejs
/**
 * Add all numbers in an array
 *
 * @param {number[]}
 * @return {number}
 */
function add(arr) {
    var sum = 0;
    for (var i = 0; i < arr.length; i++) {
        sum += arr[i];
    }
    return sum;
}
JS
10/48
Type Annotations
Explicit typing...without any checks.
@AndrewRota | #empirejs
/**
 * Add all numbers in an array
 *
 * @param {number[]}
 * @return {number}
 */
function add(arr) {
    var sum = 0;
    for (var i = 0; i < arr.length; i++) {
        sum += arr[i];
    }
    return sum;
}
JS
11/48
Code Reviews !== Type Checks
@AndrewRota | #empirejs 12/48
Type Checking in JavaScript
@AndrewRota | #empirejs 13/48
ActionScript
Early 2000s | Partially conformed to ECMAScript 4
@AndrewRota | #empirejs
private function add(arr:Array):int{
    var sum:int = 0;
    for (var i:int = 0; i < arr.length; i++) {
        sum += arr[i];
    }
    return sum;
}
AS
14/48
Closure Compiler
~2009
@AndrewRota | #empirejs
/**
 * Add all numbers in an array
 *
 * @param {number[]}
 * @return {number}
 */
function add(arr) {
    var sum = 0;
    for (var i = 0; i < arr.length; i++) {
        sum += arr[i];
    }
    return sum;
}
JS
15/48
TypeScript
2012 | Compiles to JavaScript, optional static typing
@AndrewRota | #empirejs
function add(arr:Array<number>):number{
    var sum:number = 0;
    for (var i:number = 0; i < arr.length; i++) {
        sum += arr[i];
    }
    return sum;
}
TS
16/48
Flow
2014 | Compiles to JavaScript, optional static typing
@AndrewRota | #empirejs
/* @flow */
function add(arr:Array<number>):number{
    var sum:number = 0;
    for (var i:number = 0; i < arr.length; i++) {
        sum += arr[i];
    }
    return sum;
}
FLOW
17/48
Flow Comments
2015 | Alternative to a transpile step
@AndrewRota | #empirejs
/* @flow */
function add(arr/*:Array<number>*/)/*:number*/{
    var sum/*:number*/ = 0;
    for (var i/*:number*/ = 0; i < arr.length; i++) {
        sum += arr[i];
    }
    return sum;
}
JS
18/48
Released Runtime Env. No Transpile Null Checking ES6
Closure Compiler 2009 Java ✓ X Some
TypeScript 2012 JavaScript X X Some
Flow 2014 OCaml X ✓ Some
Flow Comments 2015 OCaml ✓ ✓ Some
@AndrewRota | #empirejs 19/48
Adding Gradual Type Checks
@AndrewRota | #empirejs 20/48
Step 1: Choose a Type Checker
Step 2: Set Up a Transpile Step
Step 3: Add Type Annotations
@AndrewRota | #empirejs 21/48
Step 1: Choose a Type Checker
Step 2: Set Up a Transpile Step
Step 3: Add Type Annotations
@AndrewRota | #empirejs 22/48
TypeScript Flow
TypeScript vs. Flow
@AndrewRota | #empirejs
Released 2012
Written in JS: any OS
Community-provided
declaration files
Addtional transpiled features
(defaults, overloads)
·
·
·
·
Released 2014
Written in OCaml: OSX, Linux
Built-in null handling.
Comment-only syntax
available
·
·
·
·
23/48
Step 1: Choose a Type Checker
Step 2: Set Up a Transpile Step
Step 3: Add Type Annotations
@AndrewRota | #empirejs 24/48
Setting Up Flow
1. Install Flow from flowtype.org
2. Add transformer ( JSX or Babel ) to your build
@AndrewRota | #empirejs 25/48
Using Flow
1. Run flow check
2. Run build with transformer.
@AndrewRota | #empirejs
Check → Transform
26/48
Using Flow
@AndrewRota | #empirejs 27/48
Setting Up TypeScript
Install TypeScript with npm i ‐g typescript
@AndrewRota | #empirejs 28/48
Using TypeScript
Run tsc myFile.ts
@AndrewRota | #empirejs 29/48
Using TypeScript
@AndrewRota | #empirejs 30/48
Step 1: Choose a Type Checker
Step 2: Set Up a Transpile Step
Step 3: Add Type Annotations
@AndrewRota | #empirejs 31/48
Type Inference
Some of your work's already done!
Flow: property length: Property not found in Number
TypeScript: Property 'length' does not exist on type 'number'
@AndrewRota | #empirejs
var x = 1;
x.length;
JS
32/48
Adding Basic Types
Flow: number, string, boolean, void, Array, Function, Object, mixed, any
TypeScript: number, string, boolean, void, Array, Function, Object, any, enum
@AndrewRota | #empirejs
var x:string = 'test'; TS/FLOW
33/48
Arrays
@AndrewRota | #empirejs
var list:number[] = [1,2,3];
var anotherList:Array<number> = [1,2,3];
TS/FLOW
34/48
Union Types
ThisType | ThatType
@AndrewRota | #empirejs
var x: number | string = 0;
x = 'foo';
TS/FLOW
35/48
Null Checks
Flow has the advantage here
Flow: property x: Property cannot be accessed on possibly null value
TypeScript:  no error
@AndrewRota | #empirejs
var x = null;
x.foo;
JS
36/48
Functions
Both arguments and return values (the function itself)
@AndrewRota | #empirejs
function helloWorld(name: string):string {
   return 'Hello, ' + name;
}
function addExclamation(sentence: string):string {
    return sentence + '!';
}
addExclamation(helloWorld('EmpireJS'));
TS/FLOW
37/48
Object Literals
@AndrewRota | #empirejs
function doSomething(modelObject: {title: string}) {
   return modelObject.title;
}
doSomething({title: 'My Object!', id: 2, flag: true});
TS/FLOW
38/48
Interfaces
External interfaces via declaration files
→ Find TypeScript declarations at definitelytyped.org
@AndrewRota | #empirejs
interface Model {
    title: string
}
function doSomething(modelObject: Model) {
   return modelObject.title;
}
doSomething({title: 'My Object!', id: 2, flag: true});
TS/FLOW
39/48
And there's more!
@AndrewRota | #empirejs
Classes
Modules
Nullable Types
Generics
Polymorphism
·
·
·
·
·
40/48
But is it worth it?
@AndrewRota | #empirejs 41/48
Catch More Bugs at Compile Time
Flow: null: This type is incompatible with string
@AndrewRota | #empirejs
function helloWorld(name:string) {
    return 'Hello, ' + name;
}
helloWorld('EmpireJS');
helloWorld(null);
        
FLOW
42/48
Self-Document Code Behavior
@AndrewRota | #empirejs
function flatten (input, shallow, strict) {}
        
JS
function flatten (
    input: Array<any>,
    shallow: boolean,
    strict: boolean
): Array<any> {}
        
TS/FLOW
source: http://flowtype.org/docs/underscore.html#_
43/48
Easier to Reason About Code Flow
@AndrewRota | #empirejs
In: Number
Out: String
↗
In: String
Out: Object
↗
In: Object
Out: Boolean
44/48
- Bertrand Meyer
Correctness
“ The ability of software products to perform their exact tasks, as
defined by their specification.
@AndrewRota | #empirejs 45/48
Tooling
IntelliJ
Sublime
@AndrewRota | #empirejs 46/48
- TypeScript and the Road to 2.0
And someday it might be in JavaScript...
“ The TypeScript team is [...] looking forward to working together going
forward and creating the best tools we can for the JavaScript community.
In the long term, we will also be working to fold the best features of
these tools into ECMAScript, the standard behind JavaScript.
@AndrewRota | #empirejs 47/48
Thanks!
twitter @andrewrota
github github.com/andrewrota

Mais conteúdo relacionado

Mais procurados

Review of c_sharp2_features_part_iii
Review of c_sharp2_features_part_iiiReview of c_sharp2_features_part_iii
Review of c_sharp2_features_part_iiiNico Ludwig
 
Reconciling Functional Programming and Exceptions
Reconciling Functional Programming and ExceptionsReconciling Functional Programming and Exceptions
Reconciling Functional Programming and ExceptionsSeamus Mc Gonigle
 
JavaScripts internals #1
JavaScripts internals #1JavaScripts internals #1
JavaScripts internals #1Martin Pernica
 
All You Need to Know About Type Script
All You Need to Know About Type ScriptAll You Need to Know About Type Script
All You Need to Know About Type ScriptFolio3 Software
 
Templates exception handling
Templates exception handlingTemplates exception handling
Templates exception handlingsanya6900
 
FregeDay: Design and Implementation of the language (Ingo Wechsung)
FregeDay: Design and Implementation of the language (Ingo Wechsung)FregeDay: Design and Implementation of the language (Ingo Wechsung)
FregeDay: Design and Implementation of the language (Ingo Wechsung)Dierk König
 
Academy PRO: React JS. Typescript
Academy PRO: React JS. TypescriptAcademy PRO: React JS. Typescript
Academy PRO: React JS. TypescriptBinary Studio
 
Swift, a quick overview
Swift, a quick overviewSwift, a quick overview
Swift, a quick overviewJulian Król
 
JavaScript: Patterns, Part 3
JavaScript: Patterns, Part  3JavaScript: Patterns, Part  3
JavaScript: Patterns, Part 3Chris Farrell
 
Effective Scala: Programming Patterns
Effective Scala: Programming PatternsEffective Scala: Programming Patterns
Effective Scala: Programming PatternsVasil Remeniuk
 
Can't Dance The Lambda
Can't Dance The LambdaCan't Dance The Lambda
Can't Dance The LambdaTogakangaroo
 
Cocoa for Web Developers
Cocoa for Web DevelopersCocoa for Web Developers
Cocoa for Web Developersgeorgebrock
 
Exploring Kotlin language basics for Android App development
Exploring Kotlin language basics for Android App developmentExploring Kotlin language basics for Android App development
Exploring Kotlin language basics for Android App developmentJayaprakash R
 
JavaScript - Programming Languages course
JavaScript - Programming Languages course JavaScript - Programming Languages course
JavaScript - Programming Languages course yoavrubin
 
JavaScript: Core Part
JavaScript: Core PartJavaScript: Core Part
JavaScript: Core Part維佋 唐
 

Mais procurados (20)

Review of c_sharp2_features_part_iii
Review of c_sharp2_features_part_iiiReview of c_sharp2_features_part_iii
Review of c_sharp2_features_part_iii
 
Reconciling Functional Programming and Exceptions
Reconciling Functional Programming and ExceptionsReconciling Functional Programming and Exceptions
Reconciling Functional Programming and Exceptions
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
JavaScripts internals #1
JavaScripts internals #1JavaScripts internals #1
JavaScripts internals #1
 
All You Need to Know About Type Script
All You Need to Know About Type ScriptAll You Need to Know About Type Script
All You Need to Know About Type Script
 
Templates exception handling
Templates exception handlingTemplates exception handling
Templates exception handling
 
C#4.0 features
C#4.0 featuresC#4.0 features
C#4.0 features
 
Type Checking JavaScript
Type Checking JavaScriptType Checking JavaScript
Type Checking JavaScript
 
FregeDay: Design and Implementation of the language (Ingo Wechsung)
FregeDay: Design and Implementation of the language (Ingo Wechsung)FregeDay: Design and Implementation of the language (Ingo Wechsung)
FregeDay: Design and Implementation of the language (Ingo Wechsung)
 
Academy PRO: React JS. Typescript
Academy PRO: React JS. TypescriptAcademy PRO: React JS. Typescript
Academy PRO: React JS. Typescript
 
Start with swift
Start with swiftStart with swift
Start with swift
 
args_types
args_typesargs_types
args_types
 
Swift, a quick overview
Swift, a quick overviewSwift, a quick overview
Swift, a quick overview
 
JavaScript: Patterns, Part 3
JavaScript: Patterns, Part  3JavaScript: Patterns, Part  3
JavaScript: Patterns, Part 3
 
Effective Scala: Programming Patterns
Effective Scala: Programming PatternsEffective Scala: Programming Patterns
Effective Scala: Programming Patterns
 
Can't Dance The Lambda
Can't Dance The LambdaCan't Dance The Lambda
Can't Dance The Lambda
 
Cocoa for Web Developers
Cocoa for Web DevelopersCocoa for Web Developers
Cocoa for Web Developers
 
Exploring Kotlin language basics for Android App development
Exploring Kotlin language basics for Android App developmentExploring Kotlin language basics for Android App development
Exploring Kotlin language basics for Android App development
 
JavaScript - Programming Languages course
JavaScript - Programming Languages course JavaScript - Programming Languages course
JavaScript - Programming Languages course
 
JavaScript: Core Part
JavaScript: Core PartJavaScript: Core Part
JavaScript: Core Part
 

Destaque

Tugas manajemen pemasaran
Tugas manajemen pemasaranTugas manajemen pemasaran
Tugas manajemen pemasaran130293iin
 
Μάγια Ζαχαρίας
Μάγια ΖαχαρίαςΜάγια Ζαχαρίας
Μάγια Ζαχαρίαςnicolaidoumarina
 
Καβάφης Κωνσταντίνος
Καβάφης ΚωνσταντίνοςΚαβάφης Κωνσταντίνος
Καβάφης Κωνσταντίνοςnicolaidoumarina
 
ΟΔΟΣ ΑΡΧΙΕΠΙΣΚΟΠΟΥ ΚΥΠΡΟΥ ΛΕΟΝΤΙΟΥ Α΄
ΟΔΟΣ ΑΡΧΙΕΠΙΣΚΟΠΟΥ ΚΥΠΡΟΥ ΛΕΟΝΤΙΟΥ Α΄ΟΔΟΣ ΑΡΧΙΕΠΙΣΚΟΠΟΥ ΚΥΠΡΟΥ ΛΕΟΝΤΙΟΥ Α΄
ΟΔΟΣ ΑΡΧΙΕΠΙΣΚΟΠΟΥ ΚΥΠΡΟΥ ΛΕΟΝΤΙΟΥ Α΄nicolaidoumarina
 
An Exploration of Frameworks – and Why We Built Our Own
An Exploration of Frameworks – and Why We Built Our OwnAn Exploration of Frameworks – and Why We Built Our Own
An Exploration of Frameworks – and Why We Built Our OwnAndrew Rota
 
Short film festivals
Short film festivalsShort film festivals
Short film festivalspelboy123
 
οι Mοϊκανοί (ισαβέλλα&χριστιάνα)
οι Mοϊκανοί (ισαβέλλα&χριστιάνα)οι Mοϊκανοί (ισαβέλλα&χριστιάνα)
οι Mοϊκανοί (ισαβέλλα&χριστιάνα)nicolaidoumarina
 
Warehousing Nagpur
Warehousing NagpurWarehousing Nagpur
Warehousing Nagpurplusgrow
 
Κωνσταντίνος Καβάφης
Κωνσταντίνος ΚαβάφηςΚωνσταντίνος Καβάφης
Κωνσταντίνος Καβάφηςnicolaidoumarina
 

Destaque (20)

RENNIE COWAN - COMMERCIAL REEL
RENNIE COWAN - COMMERCIAL REEL RENNIE COWAN - COMMERCIAL REEL
RENNIE COWAN - COMMERCIAL REEL
 
RENNIE COWAN - FILMS
RENNIE COWAN - FILMSRENNIE COWAN - FILMS
RENNIE COWAN - FILMS
 
Tugas manajemen pemasaran
Tugas manajemen pemasaranTugas manajemen pemasaran
Tugas manajemen pemasaran
 
Μάγια Ζαχαρίας
Μάγια ΖαχαρίαςΜάγια Ζαχαρίας
Μάγια Ζαχαρίας
 
Καβάφης Κωνσταντίνος
Καβάφης ΚωνσταντίνοςΚαβάφης Κωνσταντίνος
Καβάφης Κωνσταντίνος
 
RENNIE COWAN PHOTOGRAPHY
RENNIE COWAN PHOTOGRAPHYRENNIE COWAN PHOTOGRAPHY
RENNIE COWAN PHOTOGRAPHY
 
RENNIE COWAN - 3D ANIMATION
RENNIE COWAN - 3D ANIMATION RENNIE COWAN - 3D ANIMATION
RENNIE COWAN - 3D ANIMATION
 
RENNIE COWAN - RED CARPET INTERVIEWS
RENNIE COWAN - RED CARPET INTERVIEWS RENNIE COWAN - RED CARPET INTERVIEWS
RENNIE COWAN - RED CARPET INTERVIEWS
 
ΟΔΟΣ ΑΡΧΙΕΠΙΣΚΟΠΟΥ ΚΥΠΡΟΥ ΛΕΟΝΤΙΟΥ Α΄
ΟΔΟΣ ΑΡΧΙΕΠΙΣΚΟΠΟΥ ΚΥΠΡΟΥ ΛΕΟΝΤΙΟΥ Α΄ΟΔΟΣ ΑΡΧΙΕΠΙΣΚΟΠΟΥ ΚΥΠΡΟΥ ΛΕΟΝΤΙΟΥ Α΄
ΟΔΟΣ ΑΡΧΙΕΠΙΣΚΟΠΟΥ ΚΥΠΡΟΥ ΛΕΟΝΤΙΟΥ Α΄
 
Wakayama 1 day
Wakayama 1 dayWakayama 1 day
Wakayama 1 day
 
Antena array
Antena arrayAntena array
Antena array
 
Passive voive
Passive voivePassive voive
Passive voive
 
An Exploration of Frameworks – and Why We Built Our Own
An Exploration of Frameworks – and Why We Built Our OwnAn Exploration of Frameworks – and Why We Built Our Own
An Exploration of Frameworks – and Why We Built Our Own
 
RENNIE COWAN - DIRECTOR REEL
RENNIE COWAN - DIRECTOR REEL RENNIE COWAN - DIRECTOR REEL
RENNIE COWAN - DIRECTOR REEL
 
Short film festivals
Short film festivalsShort film festivals
Short film festivals
 
Μαορι Αιμιλια
Μαορι ΑιμιλιαΜαορι Αιμιλια
Μαορι Αιμιλια
 
οι Mοϊκανοί (ισαβέλλα&χριστιάνα)
οι Mοϊκανοί (ισαβέλλα&χριστιάνα)οι Mοϊκανοί (ισαβέλλα&χριστιάνα)
οι Mοϊκανοί (ισαβέλλα&χριστιάνα)
 
insects world
insects worldinsects world
insects world
 
Warehousing Nagpur
Warehousing NagpurWarehousing Nagpur
Warehousing Nagpur
 
Κωνσταντίνος Καβάφης
Κωνσταντίνος ΚαβάφηςΚωνσταντίνος Καβάφης
Κωνσταντίνος Καβάφης
 

Semelhante a Why Static Type Checking is Better

TypeScript introduction to scalable javascript application
TypeScript introduction to scalable javascript applicationTypeScript introduction to scalable javascript application
TypeScript introduction to scalable javascript applicationAndrea Paciolla
 
Complete Notes on Angular 2 and TypeScript
Complete Notes on Angular 2 and TypeScriptComplete Notes on Angular 2 and TypeScript
Complete Notes on Angular 2 and TypeScriptEPAM Systems
 
Introduction to TypeScript
Introduction to TypeScriptIntroduction to TypeScript
Introduction to TypeScriptKeithMurgic
 
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.pptx
typescript.pptxtypescript.pptx
typescript.pptxZeynepOtu
 
TypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation GuideTypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation GuideNascenia IT
 
2.Getting Started with C#.Net-(C#)
2.Getting Started with C#.Net-(C#)2.Getting Started with C#.Net-(C#)
2.Getting Started with C#.Net-(C#)Shoaib Ghachi
 
Back to the Future with TypeScript
Back to the Future with TypeScriptBack to the Future with TypeScript
Back to the Future with TypeScriptAleš Najmann
 
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.
 
Beauty & the Beast - Java VS TypeScript
Beauty & the Beast - Java VS TypeScriptBeauty & the Beast - Java VS TypeScript
Beauty & the Beast - Java VS TypeScriptHendrik Ebbers
 
Nodejs & Typescript
Nodejs & TypescriptNodejs & Typescript
Nodejs & TypescriptKnoldus Inc.
 
Mobile Weekend Budapest presentation
Mobile Weekend Budapest presentationMobile Weekend Budapest presentation
Mobile Weekend Budapest presentationPéter Ádám Wiesner
 
PHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityPHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityGeorgePeterBanyard
 
Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2ndConnex
 
TensorFlow Lite (r1.5) & Android 8.1 Neural Network API
TensorFlow Lite (r1.5) & Android 8.1 Neural Network APITensorFlow Lite (r1.5) & Android 8.1 Neural Network API
TensorFlow Lite (r1.5) & Android 8.1 Neural Network APIMr. Vengineer
 

Semelhante a Why Static Type Checking is Better (20)

TypeScript introduction to scalable javascript application
TypeScript introduction to scalable javascript applicationTypeScript introduction to scalable javascript application
TypeScript introduction to scalable javascript application
 
Getting started with typescript
Getting started with typescriptGetting started with typescript
Getting started with typescript
 
Complete Notes on Angular 2 and TypeScript
Complete Notes on Angular 2 and TypeScriptComplete Notes on Angular 2 and TypeScript
Complete Notes on Angular 2 and TypeScript
 
Introduction to TypeScript
Introduction to TypeScriptIntroduction to TypeScript
Introduction to TypeScript
 
Introduction to TypeScript by Winston Levi
Introduction to TypeScript by Winston LeviIntroduction to TypeScript by Winston Levi
Introduction to TypeScript by Winston Levi
 
typescript.pptx
typescript.pptxtypescript.pptx
typescript.pptx
 
TypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation GuideTypeScript: Basic Features and Compilation Guide
TypeScript: Basic Features and Compilation Guide
 
JavaScript_introduction_upload.pdf
JavaScript_introduction_upload.pdfJavaScript_introduction_upload.pdf
JavaScript_introduction_upload.pdf
 
2.Getting Started with C#.Net-(C#)
2.Getting Started with C#.Net-(C#)2.Getting Started with C#.Net-(C#)
2.Getting Started with C#.Net-(C#)
 
Back to the Future with TypeScript
Back to the Future with TypeScriptBack to the Future with TypeScript
Back to the Future with 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
 
XAML/C# to HTML/JS
XAML/C# to HTML/JSXAML/C# to HTML/JS
XAML/C# to HTML/JS
 
Type script
Type scriptType script
Type script
 
Rits Brown Bag - TypeScript
Rits Brown Bag - TypeScriptRits Brown Bag - TypeScript
Rits Brown Bag - TypeScript
 
Beauty & the Beast - Java VS TypeScript
Beauty & the Beast - Java VS TypeScriptBeauty & the Beast - Java VS TypeScript
Beauty & the Beast - Java VS TypeScript
 
Nodejs & Typescript
Nodejs & TypescriptNodejs & Typescript
Nodejs & Typescript
 
Mobile Weekend Budapest presentation
Mobile Weekend Budapest presentationMobile Weekend Budapest presentation
Mobile Weekend Budapest presentation
 
PHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing InsanityPHP 8: Process & Fixing Insanity
PHP 8: Process & Fixing Insanity
 
Presentation 2nd
Presentation 2ndPresentation 2nd
Presentation 2nd
 
TensorFlow Lite (r1.5) & Android 8.1 Neural Network API
TensorFlow Lite (r1.5) & Android 8.1 Neural Network APITensorFlow Lite (r1.5) & Android 8.1 Neural Network API
TensorFlow Lite (r1.5) & Android 8.1 Neural Network API
 

Mais de Andrew Rota

Integrating React.js Into a PHP Application: Dutch PHP 2019
Integrating React.js Into a PHP Application: Dutch PHP 2019Integrating React.js Into a PHP Application: Dutch PHP 2019
Integrating React.js Into a PHP Application: Dutch PHP 2019Andrew Rota
 
Performant APIs with GraphQL and PHP (Dutch PHP 2019)
Performant APIs with GraphQL and PHP (Dutch PHP 2019)Performant APIs with GraphQL and PHP (Dutch PHP 2019)
Performant APIs with GraphQL and PHP (Dutch PHP 2019)Andrew Rota
 
Getting Started with GraphQL && PHP
Getting Started with GraphQL && PHPGetting Started with GraphQL && PHP
Getting Started with GraphQL && PHPAndrew Rota
 
Tutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHPTutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHPAndrew Rota
 
Building a GraphQL API in PHP
Building a GraphQL API in PHPBuilding a GraphQL API in PHP
Building a GraphQL API in PHPAndrew Rota
 
Ten practical ways to improve front-end performance
Ten practical ways to improve front-end performanceTen practical ways to improve front-end performance
Ten practical ways to improve front-end performanceAndrew Rota
 
Component Based UI Architectures for the Web
Component Based UI Architectures for the WebComponent Based UI Architectures for the Web
Component Based UI Architectures for the WebAndrew Rota
 
Client-Side Performance Monitoring (MobileTea, Rome)
Client-Side Performance Monitoring (MobileTea, Rome)Client-Side Performance Monitoring (MobileTea, Rome)
Client-Side Performance Monitoring (MobileTea, Rome)Andrew Rota
 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationAndrew Rota
 
Effectively Monitoring Client-Side Performance
Effectively Monitoring Client-Side PerformanceEffectively Monitoring Client-Side Performance
Effectively Monitoring Client-Side PerformanceAndrew Rota
 
UI Rendering at Wayfair
UI Rendering at WayfairUI Rendering at Wayfair
UI Rendering at WayfairAndrew Rota
 
Better PHP-Frontend Integration with Tungsten.js
Better PHP-Frontend Integration with Tungsten.jsBetter PHP-Frontend Integration with Tungsten.js
Better PHP-Frontend Integration with Tungsten.jsAndrew Rota
 
Tungsten.js: Building a Modular Framework
Tungsten.js: Building a Modular FrameworkTungsten.js: Building a Modular Framework
Tungsten.js: Building a Modular FrameworkAndrew Rota
 
The Complementarity of React and Web Components
The Complementarity of React and Web ComponentsThe Complementarity of React and Web Components
The Complementarity of React and Web ComponentsAndrew Rota
 
Web Components + Backbone: a Game-Changing Combination
Web Components + Backbone: a Game-Changing CombinationWeb Components + Backbone: a Game-Changing Combination
Web Components + Backbone: a Game-Changing CombinationAndrew Rota
 
Web Components and Modular CSS
Web Components and Modular CSSWeb Components and Modular CSS
Web Components and Modular CSSAndrew Rota
 

Mais de Andrew Rota (17)

Integrating React.js Into a PHP Application: Dutch PHP 2019
Integrating React.js Into a PHP Application: Dutch PHP 2019Integrating React.js Into a PHP Application: Dutch PHP 2019
Integrating React.js Into a PHP Application: Dutch PHP 2019
 
Performant APIs with GraphQL and PHP (Dutch PHP 2019)
Performant APIs with GraphQL and PHP (Dutch PHP 2019)Performant APIs with GraphQL and PHP (Dutch PHP 2019)
Performant APIs with GraphQL and PHP (Dutch PHP 2019)
 
Getting Started with GraphQL && PHP
Getting Started with GraphQL && PHPGetting Started with GraphQL && PHP
Getting Started with GraphQL && PHP
 
Tutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHPTutorial: Building a GraphQL API in PHP
Tutorial: Building a GraphQL API in PHP
 
Building a GraphQL API in PHP
Building a GraphQL API in PHPBuilding a GraphQL API in PHP
Building a GraphQL API in PHP
 
Ten practical ways to improve front-end performance
Ten practical ways to improve front-end performanceTen practical ways to improve front-end performance
Ten practical ways to improve front-end performance
 
Component Based UI Architectures for the Web
Component Based UI Architectures for the WebComponent Based UI Architectures for the Web
Component Based UI Architectures for the Web
 
Client-Side Performance Monitoring (MobileTea, Rome)
Client-Side Performance Monitoring (MobileTea, Rome)Client-Side Performance Monitoring (MobileTea, Rome)
Client-Side Performance Monitoring (MobileTea, Rome)
 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP Application
 
Effectively Monitoring Client-Side Performance
Effectively Monitoring Client-Side PerformanceEffectively Monitoring Client-Side Performance
Effectively Monitoring Client-Side Performance
 
UI Rendering at Wayfair
UI Rendering at WayfairUI Rendering at Wayfair
UI Rendering at Wayfair
 
Better PHP-Frontend Integration with Tungsten.js
Better PHP-Frontend Integration with Tungsten.jsBetter PHP-Frontend Integration with Tungsten.js
Better PHP-Frontend Integration with Tungsten.js
 
Tungsten.js: Building a Modular Framework
Tungsten.js: Building a Modular FrameworkTungsten.js: Building a Modular Framework
Tungsten.js: Building a Modular Framework
 
The Complementarity of React and Web Components
The Complementarity of React and Web ComponentsThe Complementarity of React and Web Components
The Complementarity of React and Web Components
 
Web Components + Backbone: a Game-Changing Combination
Web Components + Backbone: a Game-Changing CombinationWeb Components + Backbone: a Game-Changing Combination
Web Components + Backbone: a Game-Changing Combination
 
Bem methodology
Bem methodologyBem methodology
Bem methodology
 
Web Components and Modular CSS
Web Components and Modular CSSWeb Components and Modular CSS
Web Components and Modular CSS
 

Último

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 

Último (20)

The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

Why Static Type Checking is Better

  • 2. With JavaScript...anything is possible @AndrewRota | #empirejs 2/48
  • 3. Change all the types... @AndrewRota | #empirejs var x; // x starts undefined typeof x === 'undefined' x = 5;  // now it's is a number typeof x === 'number' x = 'five'; // now it's a string typeof x === 'string' x = true;  // now it's a boolean typeof x === 'boolean' x = {value: 'five'}; // now it's an object typeof x === 'object' JS 3/48
  • 4. We have types, but they're not static. (No type is known or declared at compile time) @AndrewRota | #empirejs 4/48
  • 5. 7 Types in JavaScript @AndrewRota | #empirejs Boolean Number String Object Symbol Null Undefined 5/48
  • 6. Most code has type expectations ...we just don't always acknowledge it. @AndrewRota | #empirejs function add(arr) {     var sum = 0;     for (var i = 0; i < arr.length; i++) {         sum += arr[i];     }     return sum; } add([2,3]); // returns 5 as expected add(['foo', 'bar']);  // returns "0foobar" (expected?) add(null);  // Throws exception: cannot read prop 'length' of null JS 6/48
  • 7. What to do? @AndrewRota | #empirejs 7/48
  • 8. Ad Hoc Runtime Checks @AndrewRota | #empirejs function add(arr) {     if (!Array.isArray(arr)) return;     var sum = 0;     for (var i = 0; i < arr.length; i++) {         if (typeof arr[i] !== 'number') return;         sum += arr[i];     }     return sum; } JS 8/48
  • 9. Ad Hoc Runtime Checks @AndrewRota | #empirejs function add(arr) {     if (!Array.isArray(arr)) throw('not an array');     var sum = 0;     for (var i = 0; i < arr.length; i++) {         if (typeof arr[i] !== 'number') throw('not a number');         sum += arr[i];     }     return sum; } JS 9/48
  • 10. Type Annotations @AndrewRota | #empirejs /**  * Add all numbers in an array  *  * @param {number[]}  * @return {number}  */ function add(arr) {     var sum = 0;     for (var i = 0; i < arr.length; i++) {         sum += arr[i];     }     return sum; } JS 10/48
  • 11. Type Annotations Explicit typing...without any checks. @AndrewRota | #empirejs /**  * Add all numbers in an array  *  * @param {number[]}  * @return {number}  */ function add(arr) {     var sum = 0;     for (var i = 0; i < arr.length; i++) {         sum += arr[i];     }     return sum; } JS 11/48
  • 12. Code Reviews !== Type Checks @AndrewRota | #empirejs 12/48
  • 13. Type Checking in JavaScript @AndrewRota | #empirejs 13/48
  • 14. ActionScript Early 2000s | Partially conformed to ECMAScript 4 @AndrewRota | #empirejs private function add(arr:Array):int{     var sum:int = 0;     for (var i:int = 0; i < arr.length; i++) {         sum += arr[i];     }     return sum; } AS 14/48
  • 15. Closure Compiler ~2009 @AndrewRota | #empirejs /**  * Add all numbers in an array  *  * @param {number[]}  * @return {number}  */ function add(arr) {     var sum = 0;     for (var i = 0; i < arr.length; i++) {         sum += arr[i];     }     return sum; } JS 15/48
  • 16. TypeScript 2012 | Compiles to JavaScript, optional static typing @AndrewRota | #empirejs function add(arr:Array<number>):number{     var sum:number = 0;     for (var i:number = 0; i < arr.length; i++) {         sum += arr[i];     }     return sum; } TS 16/48
  • 17. Flow 2014 | Compiles to JavaScript, optional static typing @AndrewRota | #empirejs /* @flow */ function add(arr:Array<number>):number{     var sum:number = 0;     for (var i:number = 0; i < arr.length; i++) {         sum += arr[i];     }     return sum; } FLOW 17/48
  • 18. Flow Comments 2015 | Alternative to a transpile step @AndrewRota | #empirejs /* @flow */ function add(arr/*:Array<number>*/)/*:number*/{     var sum/*:number*/ = 0;     for (var i/*:number*/ = 0; i < arr.length; i++) {         sum += arr[i];     }     return sum; } JS 18/48
  • 19. Released Runtime Env. No Transpile Null Checking ES6 Closure Compiler 2009 Java ✓ X Some TypeScript 2012 JavaScript X X Some Flow 2014 OCaml X ✓ Some Flow Comments 2015 OCaml ✓ ✓ Some @AndrewRota | #empirejs 19/48
  • 20. Adding Gradual Type Checks @AndrewRota | #empirejs 20/48
  • 21. Step 1: Choose a Type Checker Step 2: Set Up a Transpile Step Step 3: Add Type Annotations @AndrewRota | #empirejs 21/48
  • 22. Step 1: Choose a Type Checker Step 2: Set Up a Transpile Step Step 3: Add Type Annotations @AndrewRota | #empirejs 22/48
  • 23. TypeScript Flow TypeScript vs. Flow @AndrewRota | #empirejs Released 2012 Written in JS: any OS Community-provided declaration files Addtional transpiled features (defaults, overloads) · · · · Released 2014 Written in OCaml: OSX, Linux Built-in null handling. Comment-only syntax available · · · · 23/48
  • 24. Step 1: Choose a Type Checker Step 2: Set Up a Transpile Step Step 3: Add Type Annotations @AndrewRota | #empirejs 24/48
  • 25. Setting Up Flow 1. Install Flow from flowtype.org 2. Add transformer ( JSX or Babel ) to your build @AndrewRota | #empirejs 25/48
  • 26. Using Flow 1. Run flow check 2. Run build with transformer. @AndrewRota | #empirejs Check → Transform 26/48
  • 27. Using Flow @AndrewRota | #empirejs 27/48
  • 28. Setting Up TypeScript Install TypeScript with npm i ‐g typescript @AndrewRota | #empirejs 28/48
  • 31. Step 1: Choose a Type Checker Step 2: Set Up a Transpile Step Step 3: Add Type Annotations @AndrewRota | #empirejs 31/48
  • 32. Type Inference Some of your work's already done! Flow: property length: Property not found in Number TypeScript: Property 'length' does not exist on type 'number' @AndrewRota | #empirejs var x = 1; x.length; JS 32/48
  • 33. Adding Basic Types Flow: number, string, boolean, void, Array, Function, Object, mixed, any TypeScript: number, string, boolean, void, Array, Function, Object, any, enum @AndrewRota | #empirejs var x:string = 'test'; TS/FLOW 33/48
  • 35. Union Types ThisType | ThatType @AndrewRota | #empirejs var x: number | string = 0; x = 'foo'; TS/FLOW 35/48
  • 36. Null Checks Flow has the advantage here Flow: property x: Property cannot be accessed on possibly null value TypeScript:  no error @AndrewRota | #empirejs var x = null; x.foo; JS 36/48
  • 37. Functions Both arguments and return values (the function itself) @AndrewRota | #empirejs function helloWorld(name: string):string {    return 'Hello, ' + name; } function addExclamation(sentence: string):string {     return sentence + '!'; } addExclamation(helloWorld('EmpireJS')); TS/FLOW 37/48
  • 38. Object Literals @AndrewRota | #empirejs function doSomething(modelObject: {title: string}) {    return modelObject.title; } doSomething({title: 'My Object!', id: 2, flag: true}); TS/FLOW 38/48
  • 39. Interfaces External interfaces via declaration files → Find TypeScript declarations at definitelytyped.org @AndrewRota | #empirejs interface Model {     title: string } function doSomething(modelObject: Model) {    return modelObject.title; } doSomething({title: 'My Object!', id: 2, flag: true}); TS/FLOW 39/48
  • 40. And there's more! @AndrewRota | #empirejs Classes Modules Nullable Types Generics Polymorphism · · · · · 40/48
  • 41. But is it worth it? @AndrewRota | #empirejs 41/48
  • 42. Catch More Bugs at Compile Time Flow: null: This type is incompatible with string @AndrewRota | #empirejs function helloWorld(name:string) {     return 'Hello, ' + name; } helloWorld('EmpireJS'); helloWorld(null);          FLOW 42/48
  • 43. Self-Document Code Behavior @AndrewRota | #empirejs function flatten (input, shallow, strict) {}          JS function flatten (     input: Array<any>,     shallow: boolean,     strict: boolean ): Array<any> {}          TS/FLOW source: http://flowtype.org/docs/underscore.html#_ 43/48
  • 44. Easier to Reason About Code Flow @AndrewRota | #empirejs In: Number Out: String ↗ In: String Out: Object ↗ In: Object Out: Boolean 44/48
  • 45. - Bertrand Meyer Correctness “ The ability of software products to perform their exact tasks, as defined by their specification. @AndrewRota | #empirejs 45/48
  • 47. - TypeScript and the Road to 2.0 And someday it might be in JavaScript... “ The TypeScript team is [...] looking forward to working together going forward and creating the best tools we can for the JavaScript community. In the long term, we will also be working to fold the best features of these tools into ECMAScript, the standard behind JavaScript. @AndrewRota | #empirejs 47/48