TypeScript

March 2014

Presented by Steven Salat

# Wat? # * Developed by Microsoft * Anders Hejlsberg, lead architect of C# * Open source * Superset of JavaScript
# New Stuff * Classes * Interfaces * Namespaces/Modules * Type Checking * Generics * Inheritance * Method overloading * Arrow syntax for anon functions
# However TypeScript is a strict superset of JavaScript, so any existing JavaScript programs are also valid TypeScript programs. New features of TypeScript are optional and designed to play nicely with ES6 and future JS. Type Inference allows type checking auto-magically. So get started today!
# Give Me Code ```js // Developer.ts class Developer { name: string; hp: number; constructor(name: string) { this.name = name; this.hp = 100; } speak() { return "Hello my name is, " + this.name; } code() { this.hp = this.hp - 10; } } var dev = new Developer('Steven'); dev.speak(); // Hello my name is, Steven ``` [Code Here](http://goo.gl/J9XTjc)
# Compiled JS ```js // Developer.js var Developer = (function () { function Developer(name) { this.name = name; this.hp = 100; } Developer.prototype.speak = function () { return "Hello my name is, " + this.name; }; Developer.prototype.code = function () { this.hp = this.hp - 10; }; return Developer; })(); var dev = new Developer('Steven'); dev.speak(); // Hello my name is, Steven ``` [Code Here](http://goo.gl/J9XTjc)
# Mmk but why? * Less code === MORE * No more name space collisions * Errors happen at compile time instead of run time * Types can explain code better * ``` var days; /*OR*/ var days: number;``` * Intellisense works across multiple files/modules in VS * Real "Find References" and "Go To Definition" in VS * Works everywhere that JS does (Browsers, Node.js, etc) * Even DOM APIs are type checked via `lib.d.ts`
# Visual Studio Support * Only supported in VS 2012 and 2013 via [TS Plugin](http://www.microsoft.com/en-us/download/details.aspx?id=34790) * Probably want to get [Web Essentials](http://visualstudiogallery.msdn.microsoft.com/56633663-6799-41d7-9df7-0f2a504ca361) for tslint and auto-gen definitions for C# classes * Helpful for catching client-side errors when refactoring server-side code - think $.ajax calls * Download TypeScript definitons of your [favorite plugins](https://github.com/borisyankov/DefinitelyTyped)
# Give me the dirt * Very few editors support syntax highlighting or auto compilation besides Visual Studio * Not final 1.0 release...yet (1.0RC released Feb 2014) * Compiling .ts to .js ***might*** be slow for large projects * Existing codebase could be painful to upgrade * Change file name from .js to .ts * Probably restructure code as a module or class
# Futher Reading * [Why does TypeScript](http://www.hanselman.com/blog/WhyDoesTypeScriptHaveToBeTheAnswerToAnything.aspx) have to be the answer to anything? * [TypeScript Playground](http://www.typescriptlang.org/Playground/) lets you code online * [TypeScript Repo](http://typescript.codeplex.com/) for submitting bugs to MS