TypeScript

In a Nutshell

By Alvaro J. Genial

What is it?


Why do we need it?


How do we try it?


When can we get it?


Where do we use it?



But first,


"Let's go back,
back to the beginning"


—Hilary Duff


JavaScript

In a Nutshell

By Alvaro J. Genial

Which of these is true about JS?


  • The most popular programming language
  • Created at Netscape in the mid-90s
  • The source (code) of all evil
  • All of the above



"[The designer] reads up on
every mistake ever made in designing a programming language ,
 invents a few more,
and creates [JavaScript]."

— James Iry

Ok, JavaScript isn't great


But why?

Top JavaScript Misfeatures



  • Loose, incoherent typing
  • Unintuitive context/scope semantics
  • Complete lack of modularity
  • Incompatible substitutes for missing parts

Other Attempts at Deposing JavaScript



  • JavaScript 2.0
  • CoffeeScript
  • Dart
  • ECMAScript 6+

So, what's their problem?

Poor metaphor for JavaScript 2.0

(Everything but the kitchen sink.)

Poor metaphor for CoffeeScript


(Cute, but doesn't address the core issues.)

Poor metaphor for Dart

(The Rolls-Royce that no one will buy.)

Poor metaphor for ECMAScript 6+


(Promising but remains pie in the sky.)

So, back to TypeScript


Semi-equational Reasoning 

     JavaScript
+ Optional Type Annotations
+ Lightweight Modules
+ ECMAScript 6-esque Classes
+ Succinct, C#-ish Lambdas
+ Erasable, JVM-style Generics

≈ TypeScript

Optional Type Annotations

JavaScript

function repeat(s) {
    return s + s;
}

function square(x) {
    return x * x;
}

TypeScript

function repeat(s: string) : string {
    return s + s;
}

function square(x: number) : number {
    return x * x;
}

Lightweight Modules

JavaScript

var foo = (function() {
    return {
        Bar: ...
    };
})();

TypeScript

module foo {
    export class Bar {
        // ...
    }
}

ECMAScript 6-esque Classes

JavaScript

var Greeter = (function () {
    function Greeter(message) {
        this.greeting = message;
    }
    Greeter.prototype.greet = function () {
        return "Hello, " + this.greeting;
    };
    return Greeter;
})();

TypeScript

class Greeter {
    greeting: string;
    constructor(message: string) {
        this.greeting = message;
    }
    greet() {
        return "Hello, " + this.greeting;
    }
}

Succinct, C#-ish Lambdas

JavaScript

function(x, y, z) {   return [x, y, z];}

TypeScript

(x, y, z) => [x, y, z]

However, note that




TypeScript ⊋ JavaScript

(Obtuse way to say TS is a strict superset of JS.)


So, existing JS is automatically valid TS.

Will it float?



  • Pragmatic, backwards-compatible design
  • Open source & commercial tooling support
  • Growing contributions from the community
  • Anders Hejlsberg's record (Turbo Pascal, C#)
  • Microsoft's patronage

Signs point to yes.

What is it?

small,  modular, type-friendly superset of JavaScript.

Why do we need it?

As applications grow, JavaScript quickly becomes unwieldy.

How do we try it?

http://www.typescriptlang.org/Playground/

When can we get it?

It's already available, including support for Node and Visual Studio.

Where do we use it?

Everywhere; especially in large-scale applications.

Poor metaphor for TypeScript


(A reliable, practical tool you can use right now.) 

Thanks—That is all

http://alva.ro

License

By