Target: Easy script interaction for hobby programmers in the browser, who can’t write Java • 1996 handed over to ECMA for standardization • ECMAScript 5 (spec. 1999) supported by all browsers (>=IE9)
= 'bar'; const foo: string = 'bar'; var let const scope function block block immutable No No Yes Standard ever ES2015 / TS ES2015 / TS Usecase Not any more ~30% ~70%
string) { this.name = name; } } class Employee extends Person { private department: string; constructor(name: string, department: string) { super(name); this.department = department; } public getElevatorPitch() { return `Hello, my name is ${this.name} and I work in $ {this.department}.`; } } let howard = new Employee("Howard", "Sales"); console.log(howard.getElevatorPitch()); console.log(howard.name); // error
interface SelectableControl extends Control { select(): void; } class Button extends Control { select() { } } class TextBox extends Control { select() { } } class Image extends Control { } class Location { select() { } }
function box <T> (content: T): Box<T> { const myBox = new Box<T>(content); return myBox; } box<Cake>(new Cake()) // a box with a cake box<Phone>(new Phone()) // a box with a phone box(new Cake()) // also a box with a cake => inference
• Typedefinition files [library].d.ts provide typed interfaces for TypeScript • Typings is a Definition Manager that loads, updates and maintains definition files https://github.com/Microsoft/TypeScriptSamples/tree/master/jquery