1 of 14

TypeScript

with Tom von Clef

KnoxvilleJS

April 21, 2014

2 of 14

About Me

Programming Since Age 11

At the Electric Power Research Institute

Software Developer with 5 years experience

Finished BS in Comp Sci from UT in 2012

Mostly full-stack web development

3 of 14

My Project

Ridiculous Project Deadline

  • No postback client-side with AJAX queries
  • ~400 lines of JS
  • Previous iteration was hurried
  • Needed to quickly add much more
  • Getting hard to work with
  • So I turned to...

4 of 14

TypeScript!

JavaScript enhanced for large applications

  • Strict superset of JavaScript
  • Optional static types, OOP, and modules
  • Produces clean, idiomatic JavaScript

5 of 14

TypeScript Background

  • Microsoft led project, first announced in Oct 2012
  • At version 1.0 (April 2 release)
  • Included in Visual Studio 2013 (extension for VS2012). Also node.js. And Sublime Text, Vi, Emacs, syntax files
  • Open Source (Apache License 2.0)
  • Created by Anders Hejlsberg

6 of 14

Anders Hejlsburg

  • Original author of Turbo Pascal
  • Chief architect of Delphi
  • Lead architect of C#
  • Now… TypeScript

7 of 14

The TypeScript Playground

TypeScript compiler written in TypeScript

http://www.typescriptlang.org/Playground/#src=

8 of 14

TypeScript features...

Type Annotations

Compile Time Checking

Classes

Inheritance

Interfaces

Modules

Enums

Generics

Function Expressions

...make JavaScript feel like C#

9 of 14

TypeScript Advantages

  • Low Risk: Idiomatic & pretty JavaScript output
    • Easy to debug
    • Makes it simple to migrate to/from TypeScript
  • Better structuring: modules, classes, interfaces
  • No inadvertent globals, other “Bad Parts”
  • ES6 now (classes, modules…)
  • Optional types offer
    • Compile time checks
    • Auto-complete
    • Automatic type inference

10 of 14

TypeScript Disadvantages

  • Hard to name many disadvantages, since it is a superset of JavaScript
  • But it does require that extra compile step and source-mapping
  • Lack of type union

11 of 14

DefinitelyTyped

  • Types for 375+ JS libraries
  • From 401 contributors
  • https://github.com/borisyankov/DefinitelyTyped
  • Submitted something for jquery.flot.js
  • It’s cool getting your own code back through NuGet

12 of 14

My Plan for Future Use of TypeScript

  • Going forward
    • Won’t use TypeScript for < 200 lines JavaScript
    • …but they can easily be converted to TS if they get larger.
    • Plan to use it for larger web applications

13 of 14

Where to Go Next

14 of 14

Questions?