Typescript - making Javascript safe

Phil Denoncourt



Sample Code

Javascript is hard

  • Unstructured nature leads to unstructured code
  • Complex enterprise apps have high maintainability problems

The answer is..


  • EMCAScript 6 will support classes
  • Typescript is essentially a preview of EMCAScript 6


  • Superset of Javascript
  • Developed by Microsoft
  • Architected by Anders Hejlsberg
  • "Compiles" to Javascript (ES 3 or 5)

Typescript Features

Almost anything that is Javascript is valid Typescript

Type inference gets in the way

Type Safety

  • Typescript makes inferences about all variables
  • Supports 6 native types
    • Number
    • String
    • Boolean
    • Void
    • Null
    • Undefined


  • Solves the issue of global namespace pollution.
  • Equivalent of Namespace


  • Adds support for structured objects
  • Strictly a compile time check
  • No support to test if object implements interface


  • Supports typical class-like features:
    • Inheritance (Single class, multiple interfaces)
    • Constructors
    • Public/Private Assessibility(Compiletime checks)
    • Properties (EMCAScript 5 and higher)
    • Methods
    • Static fields & methods

More inituitive 'this'

  • Scoping is non-intuitive to .NET developers
  • that=this; -or- self=this;littered through source.
  • this means current instance of class in Typescript.

Lambda definition of functions

  • Familiar syntax to .NET developers
  • Preserves the context of 'this'



Why Typescript is better

  • You already know Javascript
  • Moving in step with EMCAScript 6
  • Supported by a company with larger support staff

vs. Coffeescript

  • Completely different Language
  • Sometimes it's difficult to pinpoint source of the Javascript
  • *but*
  • Does replace == with ===
  • Better iterations
  • Typically fewer lines of code

vs. Dart

  • Also a completely different language
  • Tooling is not widespread


  • Addon support for Visual Studio
    • Provides intellisense and navigation.
    • Still rudimentary.
  • Web Essentials extension
    • Adds ability to automatically compile when saved.
    • Adds support for regions
  • Resharper support targeted for 8.1
  • WebStorm by Jetbrains also supports Typescript.


  • It's just Javascript
  • Can use map files to step through typescript.