SlideShare a Scribd company logo
2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now
TypeScript
JavaScript that scales.
Do you feel lucky to have skipped the dreadful Java/C# legacy stuff?
Costas Stergiou, www.ImageAccessCorp.com
www.typescriptlang.org
2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now
Introduction
Who are we? Our main product
Document Capture Software
www.ImageAccessCorp.com
2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now
Why does it matter who we are and who
our customers are?
• <sales_pitch_alert> Well, we are kind of proud <sales_pitch_alert/>
• You need to understand the perspective of what you are about to hear.
It's important to know:
– who is one talking to you and what he has done in his dev-lifetime
– what are the real-life, business problems we solved
– Who are the customers that trust us?
• These same rules should apply for everything you read or hear on the
Internet
2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now
Presentation agenda
• The challenge we faced
• The problem with JavaScript
• TypeScript as the rescue
• Quick facts about TypeScript
• Why would any of you today care about TypeScript
2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now
Our challenge: rewrite the client in HTML5
• Current Client written in Java, ~300K LOC, 1200 classes in 600 source files
• We needed an application running in the browser, not a web-page
• Enterprise-level requirements: performance, scalability, future-proof
• Also does native stuff (image processing, native APIs) not doable within
the browser
Team challenges
• No prior serious experience with 'modern' web development, lots of
experience in 'legacy' development
• JavaScript, JavaScript & JavaScript
• JavaScript EcoSystem …
2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now
JavaScript, not the tool for the job
Quotes from an interview Brendan Eich (creator of JavaScript):
• JavaScript was originally developed for applications with a few hundred
lines of code! Netscape, 1995
• … the idea was to make it a complementary scripting language to go
with Java, with the compiled language …and we were pushing it as a
little brother to Java, as a complementary language like Visual Basic was
to C++ in Microsoft’s language families at the time
• … to make something that Web designers, people who may or may not
have much programming training, could use to add a little bit of
animation or a little bit of smarts to their Web forms and their Web
pages.
2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now
JavaScript Ecosystem
• It took 3-6 months of researching
• It took a lot of internal discussions
to see through the 'hype'
• We tested several 'frameworks',
'libraries', 'technologies', etc to
understand what the problem is
each one is trying to solve
• Best solution seemed the Google
Closure library
2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now
Hackernoon.com: 5 Best JavaScript
Frameworks in 2017
2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now
…and here comes TypeScript
1. Maintainability
2. Scalability (understanding intent)
3. Developer Productivity
– Code navigation
– Bug prevention
– Code 'discoverability' & refactoring
4. Performance (WebAssembly?)
"Always code as if the guy who ends up
maintaining your code will be a violent
psychopath who knows where you live."
"Any fool can write code that a computer
can understand. Good programmers write
code that humans can understand." Kent Beck
“Writing dumb code is hard
2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now
Why types matter?
What is wrong with this?function add(a, b){
return a + b;
}
add(2,3);
add(2, "3");
add("Java", "Script");
add("ES", 6);
add("ES", "6");
add(true, 6);
add(false+1, true-null);
add(0, undefined);
add("0", undefined);
add({}, 1);
add(1, {});
add(Array, 0);
add(1);
2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now
This is what a JS engine has to do
2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now
TypeScript "saved our day"
• Confidence to start a large project
• Developer tools to support a team (refactor, debugging, etc)
• Easy "migration" from an existing object-oriented code base
• For the past 2 years, it proved the best decision we made
TypeScript…a language that is trying its best
to help developers not write "bad" code
2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now
TypeScript facts
– "Javascript that Scales." (https://www.typescriptlang.org/)
"Typescript is a superset of JavaScript that compiles to plain
JavaScript"
– Developed by Microsoft (Anders Hejlsberg)
– Open source
– Written itself in TypeScript
– Transpiles to JavaScript
– Google withdraw AtScript in 2014 in favor of TypeScript
2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now
TypeScript Goals
1. Statically identify constructs that are likely to be errors.
2. Provide a structuring mechanism for larger pieces of code.
3. Impose no runtime overhead on emitted programs.
4. Emit clean, idiomatic, recognizable JavaScript code.
5. Produce a language that is composable and easy to reason about.
6. Align with current and future ECMAScript proposals.
7. Preserve runtime behavior of all JavaScript code.
8. Avoid adding expression-level syntax.
9. Use a consistent, fully erasable, structural type system.
10. Be a cross-platform development tool.
11. Do not cause substantial breaking changes from TypeScript 1.0.
2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now
Why would I want it? (1/2)
function GreeceJSBookingApi(config) {
/* noone will ever know what I intended to write here */
}
var bookIt = GreeceJSBookingApi({monitors: 4, isHuge: true, roomShape: "oval"});
/**
* The GreeceJSBookingApi is cool and you have to use it
* @param {Object} config A bunch of options I dreamt of today
* @returns {Object} the results of my fancy API
*/
1. How do I document the config properties or the return value?
2. How do I make the config object optional?
3. How do I maintain and enforce the above?
2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now
/**
* The GreeceJSApi is cool and you have to use it
* @param {Object} config A bunch of option I need today
* @returns {Object} the results of my fancy API
*/
function GreeceJSBookingApi(config?: GreeceJSBookingApiConfig):
GreeceJSBookingApiResult {
/* noone will ever know what I intended to write here */
}
interface GreeceJSBookingApiConfig {
/**
* the number of monitors I want to have in the room
*/
monitors: number;
/**
* Whether I want to reserve the huge room
*/
isHuge: boolean;
/**
* What arrangement of chairs do I need?
*/
roomShape: string;
}
interface GreeceJSBookingApiResult {
/**
* The date & time of the booking
*/
bookingDate: Date;
/**
* whether I need to confirm it the previous day
*/
needConfirmation: boolean;
/**
* an array of names & phone numbers of organizers
* I may call if something goes wrong
*/
contactPhones: [{name: string, number: string}];
}
Why would I want it? (2/2)
2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now
What does TypeScript has over JavaScript?
• Class system (similar to ES2015), with types in constructor and properties
getters/setters
• Interfaces (erased from runtime)
• Own module system (import/export), similar to ES2015 (CommonJS,
AMD, system, umd)
• Optional types
• Decorators (similar to annotations)
• Type system (compile type only, structural typing and type inference)
• Generics
• Promises (similar to ES2015)
• async/await support (similar to ES2016)
• Outputs es3, es5, es2015, es2016, es2017 code
• Solid support (VSCode), debugging and transpiling tools
2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now
TypeScript EcoSystem
• Community
– 9th most popular lang in SO in 2017
– 3rd mose loved lang is in 2017
– DefinitelyTypes (e.g. npm install
@types/react)
– SO: Kotlin, R and TypeScript among least
disliked programming languages (people
dislike Perl, Delphi, VBA, objective-c, c#,
java)
• Frameworks
– Angular, Ember, Dojo2, RxJS
• Tool Support
– VS, IntelliJ, Sublime, Atom, Ecliplse
2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now
Getting Started
www.typescriptlang.org
$ npm install –g typescript
$ mv mycode.js mycode.ts
$ tsc mycode.ts
… the more lines of code a human
writes, the more inevitable it
becomes to misspell a property,
assume the parent of a nested
object to always exist, or to use a
non-standard error object.
2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now
“Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it.”
Brian Kernighan
Rule of thumb for estimating the completion time of software projects:
• 1/3 time for planning
• 1/6 time for coding
• 1/4 time for component tests
• 1/4 time for system test with all components in hand
50% of time goes to testing & debugging
from The 'Mythical Man-Month' by Frederick P. Brooks, Jr.
2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now
Questions

More Related Content

Similar to TypeScript: JavaScript that scales (Kostas Stergiou) - GreeceJS #22 (20)

PDF
Type script vs javascript come face to face in battleground
Katy Slemon
 
PPTX
TypeScript VS JavaScript.pptx
Albiorix Technology
 
PPTX
Typescript: JS code just got better!
amit bezalel
 
PPTX
Moving From JavaScript to TypeScript: Things Developers Should Know
Fibonalabs
 
PDF
Reasons to Use Typescript for Your Next Project Over Javascript.pdf
MobMaxime
 
PPTX
The advantage of developing with TypeScript
Corley S.r.l.
 
PDF
4Developers: Tomasz Ducin- JavaScript + Java = TypeScript
PROIDEA
 
PDF
TypeScript introduction to scalable javascript application
Andrea Paciolla
 
PDF
Introduction to TypeScript
NexThoughts Technologies
 
PDF
TypeScipt - Get Started
Krishnanand Sivaraj
 
PPTX
Type script
Mallikarjuna G D
 
PPTX
Getting started with typescript
C...L, NESPRESSO, WAFAASSURANCE, SOFRECOM ORANGE
 
PDF
(Ebook) Programming TypeScript: Making Your JavaScript Applications Scale by ...
douteysakpe40
 
PDF
An Introduction to TypeScript: Definition, History, and Key Features
Michael Coplin
 
PDF
What is TypeScript? It's Definition, History And Features
HarryParker32
 
PPTX
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Malla Reddy University
 
PPTX
TypeScript Introduction
Travis van der Font
 
PDF
Typescript for the programmers who like javascript
Andrei Sebastian Cîmpean
 
PDF
TypeScript Vs. JavaScript: Which Is Best?
Marrie Morris
 
PPTX
TypeScript: Bringing Sanity to JavaScript
Dave Fancher
 
Type script vs javascript come face to face in battleground
Katy Slemon
 
TypeScript VS JavaScript.pptx
Albiorix Technology
 
Typescript: JS code just got better!
amit bezalel
 
Moving From JavaScript to TypeScript: Things Developers Should Know
Fibonalabs
 
Reasons to Use Typescript for Your Next Project Over Javascript.pdf
MobMaxime
 
The advantage of developing with TypeScript
Corley S.r.l.
 
4Developers: Tomasz Ducin- JavaScript + Java = TypeScript
PROIDEA
 
TypeScript introduction to scalable javascript application
Andrea Paciolla
 
Introduction to TypeScript
NexThoughts Technologies
 
TypeScipt - Get Started
Krishnanand Sivaraj
 
Type script
Mallikarjuna G D
 
Getting started with typescript
C...L, NESPRESSO, WAFAASSURANCE, SOFRECOM ORANGE
 
(Ebook) Programming TypeScript: Making Your JavaScript Applications Scale by ...
douteysakpe40
 
An Introduction to TypeScript: Definition, History, and Key Features
Michael Coplin
 
What is TypeScript? It's Definition, History And Features
HarryParker32
 
Unit 1 - TypeScript & Introduction to Angular CLI.pptx
Malla Reddy University
 
TypeScript Introduction
Travis van der Font
 
Typescript for the programmers who like javascript
Andrei Sebastian Cîmpean
 
TypeScript Vs. JavaScript: Which Is Best?
Marrie Morris
 
TypeScript: Bringing Sanity to JavaScript
Dave Fancher
 

More from GreeceJS (19)

PDF
Introduction to react-query. A Redux alternative? (Nikos Kleidis, Front End D...
GreeceJS
 
PDF
Next.js and the pursuit of happiness (Dimitris Michalakos, Lead Developer at ...
GreeceJS
 
PDF
An Emoji Introduction to React Native (Panagiotis Vourtsis, Senior Front End ...
GreeceJS
 
PDF
Under the hood of RxJS (Dimitris Livas) - GreeceJS #27
GreeceJS
 
PDF
All About GRAND Stack: GraphQL, React, Apollo, and Neo4j (Mark Needham) - Gre...
GreeceJS
 
PDF
Cross platform engineering - Lessons Learned (Michael Asimakopoulos, Valadis ...
GreeceJS
 
PDF
Migrating from Monolithic to Serverless (Kostas Katsikas) - GreeceJS #22
GreeceJS
 
PDF
Taming forms with React
GreeceJS
 
PDF
The JavaScript toolset for development on Ethereum
GreeceJS
 
PDF
Modern web development and accessibility (Christina Papadimitriou, Nadia Mark...
GreeceJS
 
PDF
Cycle.js - Functional reactive UI framework (Nikos Kalogridis)
GreeceJS
 
PDF
React Native and the future of web technology (Mark Wilcox) - GreeceJS #15
GreeceJS
 
PPTX
The rise of Polymer and Web Components (Kostas Karolemeas) - GreeceJS #17
GreeceJS
 
PPTX
Challenges of angular in production (Tasos Bekos) - GreeceJS #17
GreeceJS
 
PDF
The case for HTTP/2
GreeceJS
 
PDF
GraphQL vs REST
GreeceJS
 
PPTX
Ellak JavaScript Day
GreeceJS
 
PPTX
The history of asynchronous JavaScript
GreeceJS
 
PDF
The tools & technologies behind Resin.io
GreeceJS
 
Introduction to react-query. A Redux alternative? (Nikos Kleidis, Front End D...
GreeceJS
 
Next.js and the pursuit of happiness (Dimitris Michalakos, Lead Developer at ...
GreeceJS
 
An Emoji Introduction to React Native (Panagiotis Vourtsis, Senior Front End ...
GreeceJS
 
Under the hood of RxJS (Dimitris Livas) - GreeceJS #27
GreeceJS
 
All About GRAND Stack: GraphQL, React, Apollo, and Neo4j (Mark Needham) - Gre...
GreeceJS
 
Cross platform engineering - Lessons Learned (Michael Asimakopoulos, Valadis ...
GreeceJS
 
Migrating from Monolithic to Serverless (Kostas Katsikas) - GreeceJS #22
GreeceJS
 
Taming forms with React
GreeceJS
 
The JavaScript toolset for development on Ethereum
GreeceJS
 
Modern web development and accessibility (Christina Papadimitriou, Nadia Mark...
GreeceJS
 
Cycle.js - Functional reactive UI framework (Nikos Kalogridis)
GreeceJS
 
React Native and the future of web technology (Mark Wilcox) - GreeceJS #15
GreeceJS
 
The rise of Polymer and Web Components (Kostas Karolemeas) - GreeceJS #17
GreeceJS
 
Challenges of angular in production (Tasos Bekos) - GreeceJS #17
GreeceJS
 
The case for HTTP/2
GreeceJS
 
GraphQL vs REST
GreeceJS
 
Ellak JavaScript Day
GreeceJS
 
The history of asynchronous JavaScript
GreeceJS
 
The tools & technologies behind Resin.io
GreeceJS
 
Ad

Recently uploaded (20)

PDF
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PPTX
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PPTX
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Ad

TypeScript: JavaScript that scales (Kostas Stergiou) - GreeceJS #22

  • 1. 2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now TypeScript JavaScript that scales. Do you feel lucky to have skipped the dreadful Java/C# legacy stuff? Costas Stergiou, www.ImageAccessCorp.com www.typescriptlang.org
  • 2. 2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now Introduction Who are we? Our main product Document Capture Software www.ImageAccessCorp.com
  • 3. 2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now Why does it matter who we are and who our customers are? • <sales_pitch_alert> Well, we are kind of proud <sales_pitch_alert/> • You need to understand the perspective of what you are about to hear. It's important to know: – who is one talking to you and what he has done in his dev-lifetime – what are the real-life, business problems we solved – Who are the customers that trust us? • These same rules should apply for everything you read or hear on the Internet
  • 4. 2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now Presentation agenda • The challenge we faced • The problem with JavaScript • TypeScript as the rescue • Quick facts about TypeScript • Why would any of you today care about TypeScript
  • 5. 2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now Our challenge: rewrite the client in HTML5 • Current Client written in Java, ~300K LOC, 1200 classes in 600 source files • We needed an application running in the browser, not a web-page • Enterprise-level requirements: performance, scalability, future-proof • Also does native stuff (image processing, native APIs) not doable within the browser Team challenges • No prior serious experience with 'modern' web development, lots of experience in 'legacy' development • JavaScript, JavaScript & JavaScript • JavaScript EcoSystem …
  • 6. 2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now JavaScript, not the tool for the job Quotes from an interview Brendan Eich (creator of JavaScript): • JavaScript was originally developed for applications with a few hundred lines of code! Netscape, 1995 • … the idea was to make it a complementary scripting language to go with Java, with the compiled language …and we were pushing it as a little brother to Java, as a complementary language like Visual Basic was to C++ in Microsoft’s language families at the time • … to make something that Web designers, people who may or may not have much programming training, could use to add a little bit of animation or a little bit of smarts to their Web forms and their Web pages.
  • 7. 2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now JavaScript Ecosystem • It took 3-6 months of researching • It took a lot of internal discussions to see through the 'hype' • We tested several 'frameworks', 'libraries', 'technologies', etc to understand what the problem is each one is trying to solve • Best solution seemed the Google Closure library
  • 8. 2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now Hackernoon.com: 5 Best JavaScript Frameworks in 2017
  • 9. 2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now …and here comes TypeScript 1. Maintainability 2. Scalability (understanding intent) 3. Developer Productivity – Code navigation – Bug prevention – Code 'discoverability' & refactoring 4. Performance (WebAssembly?) "Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." "Any fool can write code that a computer can understand. Good programmers write code that humans can understand." Kent Beck “Writing dumb code is hard
  • 10. 2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now Why types matter? What is wrong with this?function add(a, b){ return a + b; } add(2,3); add(2, "3"); add("Java", "Script"); add("ES", 6); add("ES", "6"); add(true, 6); add(false+1, true-null); add(0, undefined); add("0", undefined); add({}, 1); add(1, {}); add(Array, 0); add(1);
  • 11. 2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now This is what a JS engine has to do
  • 12. 2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now TypeScript "saved our day" • Confidence to start a large project • Developer tools to support a team (refactor, debugging, etc) • Easy "migration" from an existing object-oriented code base • For the past 2 years, it proved the best decision we made TypeScript…a language that is trying its best to help developers not write "bad" code
  • 13. 2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now TypeScript facts – "Javascript that Scales." (https://www.typescriptlang.org/) "Typescript is a superset of JavaScript that compiles to plain JavaScript" – Developed by Microsoft (Anders Hejlsberg) – Open source – Written itself in TypeScript – Transpiles to JavaScript – Google withdraw AtScript in 2014 in favor of TypeScript
  • 14. 2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now TypeScript Goals 1. Statically identify constructs that are likely to be errors. 2. Provide a structuring mechanism for larger pieces of code. 3. Impose no runtime overhead on emitted programs. 4. Emit clean, idiomatic, recognizable JavaScript code. 5. Produce a language that is composable and easy to reason about. 6. Align with current and future ECMAScript proposals. 7. Preserve runtime behavior of all JavaScript code. 8. Avoid adding expression-level syntax. 9. Use a consistent, fully erasable, structural type system. 10. Be a cross-platform development tool. 11. Do not cause substantial breaking changes from TypeScript 1.0.
  • 15. 2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now Why would I want it? (1/2) function GreeceJSBookingApi(config) { /* noone will ever know what I intended to write here */ } var bookIt = GreeceJSBookingApi({monitors: 4, isHuge: true, roomShape: "oval"}); /** * The GreeceJSBookingApi is cool and you have to use it * @param {Object} config A bunch of options I dreamt of today * @returns {Object} the results of my fancy API */ 1. How do I document the config properties or the return value? 2. How do I make the config object optional? 3. How do I maintain and enforce the above?
  • 16. 2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now /** * The GreeceJSApi is cool and you have to use it * @param {Object} config A bunch of option I need today * @returns {Object} the results of my fancy API */ function GreeceJSBookingApi(config?: GreeceJSBookingApiConfig): GreeceJSBookingApiResult { /* noone will ever know what I intended to write here */ } interface GreeceJSBookingApiConfig { /** * the number of monitors I want to have in the room */ monitors: number; /** * Whether I want to reserve the huge room */ isHuge: boolean; /** * What arrangement of chairs do I need? */ roomShape: string; } interface GreeceJSBookingApiResult { /** * The date & time of the booking */ bookingDate: Date; /** * whether I need to confirm it the previous day */ needConfirmation: boolean; /** * an array of names & phone numbers of organizers * I may call if something goes wrong */ contactPhones: [{name: string, number: string}]; } Why would I want it? (2/2)
  • 17. 2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now What does TypeScript has over JavaScript? • Class system (similar to ES2015), with types in constructor and properties getters/setters • Interfaces (erased from runtime) • Own module system (import/export), similar to ES2015 (CommonJS, AMD, system, umd) • Optional types • Decorators (similar to annotations) • Type system (compile type only, structural typing and type inference) • Generics • Promises (similar to ES2015) • async/await support (similar to ES2016) • Outputs es3, es5, es2015, es2016, es2017 code • Solid support (VSCode), debugging and transpiling tools
  • 18. 2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now TypeScript EcoSystem • Community – 9th most popular lang in SO in 2017 – 3rd mose loved lang is in 2017 – DefinitelyTypes (e.g. npm install @types/react) – SO: Kotlin, R and TypeScript among least disliked programming languages (people dislike Perl, Delphi, VBA, objective-c, c#, java) • Frameworks – Angular, Ember, Dojo2, RxJS • Tool Support – VS, IntelliJ, Sublime, Atom, Ecliplse
  • 19. 2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now Getting Started www.typescriptlang.org $ npm install –g typescript $ mv mycode.js mycode.ts $ tsc mycode.ts … the more lines of code a human writes, the more inevitable it becomes to misspell a property, assume the parent of a nested object to always exist, or to use a non-standard error object.
  • 20. 2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now “Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” Brian Kernighan Rule of thumb for estimating the completion time of software projects: • 1/3 time for planning • 1/6 time for coding • 1/4 time for component tests • 1/4 time for system test with all components in hand 50% of time goes to testing & debugging from The 'Mythical Man-Month' by Frederick P. Brooks, Jr.
  • 21. 2018 Image Access Corp. All rights reserved WARNING: Once you go with TypeScript you won't go back to plain old JavaScript ever again; if unsure leave now Questions