TypeScript = JavaScript (almost) done right Maurice de Beijer
Who am I  Maurice de Beijer  The Problem Solver  Microsoft MVP since 2005  DevelopMentor instructor  Twitter: @mauricedb  Blog: http://msmvps.com/blogs/theproblemsolver/  Web: http://www.HTML5Support.nl  E-mail: Maurice.de.Beijer@gmail.com
Agenda  What is TypeScript?  Why do we need TypeScript?  What is wrong with JavaScript?  TypeScript features  Type annotations  Type inference  Modules  Classes
What is TypeScript?  An open source programming language developed at Microsoft  By Anders Hejlsberg, lead architect of C#  A super set of JavaScript  All JavaScript is valid TypeScript  Adds optional type checking, classes, interfaces and more  Compiles to “normal” JavaScript  Either ECMAScript 5 or ECMAScipt 3
Why do we need TypeScript?  JavaScript was designed for small scripts  These days JavaScript applications get bigger and more complex  Gmail is reported to have 443,000 lines of JavaScript in 2010  This trend will continue  Single Page Applications in the browser  Node.js on the server
What is wrong with JavaScript?
Douglas Crockford on TypeScript Microsoft's TypeScript may be the best of the many JavaScript front ends. It seems to generate the most attractive code. And I think it should take pressure off of the ECMAScript Standard for new features like type declarations and classes. Anders has shown that these can be provided nicely by a preprocessor, so there is no need to change the underlying language. I think that JavaScript's loose typing is one of its best features and that type checking is way overrated. TypeScript adds sweetness, but at a price. It is not a price I am willing to pay.
Things TypeScript adds to JavaScript  Type annotations  Type inference  Modules  Classes  Interfaces  Based on the ECMAScript 6 proposed standard
Type annotations
Type inference
Type annotations/arrays
Type annotations/param arrays
Arrow functions
Type annotations/casts
TypeScript type definitions  The DOM and standard JavaScript types are provided
DefinitelyTyped
Modules
Interfaces
Interfaces
Interfaces & function overloading
Interfaces & type definitions
Classes
Classes & constructors
Classes & constructors
Classes & properties
Arrow functions revisited
Arrow functions revisited
Classes & inheritance
TypeScript is still JavaScript  Not all JavaScript problems are solved by TypeScript  Some older browsers support ECMAScript 3 (December 1999)  Some older browsers have non standard DOM/CSS implementations  jQuery remains an extremely useful library
Conclusion  TypeScript is not perfect  But it helps a lot  You are not forced to use a new language  Leverage existing JavaScript skills en libraries  Consider it for your next “large“ JavaScript project  After all the risk is small

Type script = javascript (alomst) done right

  • 1.
    TypeScript = JavaScript(almost) done right Maurice de Beijer
  • 2.
    Who am I Maurice de Beijer  The Problem Solver  Microsoft MVP since 2005  DevelopMentor instructor  Twitter: @mauricedb  Blog: http://msmvps.com/blogs/theproblemsolver/  Web: http://www.HTML5Support.nl  E-mail: Maurice.de.Beijer@gmail.com
  • 3.
    Agenda  What isTypeScript?  Why do we need TypeScript?  What is wrong with JavaScript?  TypeScript features  Type annotations  Type inference  Modules  Classes
  • 4.
    What is TypeScript? An open source programming language developed at Microsoft  By Anders Hejlsberg, lead architect of C#  A super set of JavaScript  All JavaScript is valid TypeScript  Adds optional type checking, classes, interfaces and more  Compiles to “normal” JavaScript  Either ECMAScript 5 or ECMAScipt 3
  • 5.
    Why do weneed TypeScript?  JavaScript was designed for small scripts  These days JavaScript applications get bigger and more complex  Gmail is reported to have 443,000 lines of JavaScript in 2010  This trend will continue  Single Page Applications in the browser  Node.js on the server
  • 6.
    What is wrongwith JavaScript?
  • 7.
    Douglas Crockford onTypeScript Microsoft's TypeScript may be the best of the many JavaScript front ends. It seems to generate the most attractive code. And I think it should take pressure off of the ECMAScript Standard for new features like type declarations and classes. Anders has shown that these can be provided nicely by a preprocessor, so there is no need to change the underlying language. I think that JavaScript's loose typing is one of its best features and that type checking is way overrated. TypeScript adds sweetness, but at a price. It is not a price I am willing to pay.
  • 8.
    Things TypeScript addsto JavaScript  Type annotations  Type inference  Modules  Classes  Interfaces  Based on the ECMAScript 6 proposed standard
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
    TypeScript type definitions The DOM and standard JavaScript types are provided
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
    Interfaces & typedefinitions
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
    TypeScript is stillJavaScript  Not all JavaScript problems are solved by TypeScript  Some older browsers support ECMAScript 3 (December 1999)  Some older browsers have non standard DOM/CSS implementations  jQuery remains an extremely useful library
  • 30.
    Conclusion  TypeScript isnot perfect  But it helps a lot  You are not forced to use a new language  Leverage existing JavaScript skills en libraries  Consider it for your next “large“ JavaScript project  After all the risk is small