Hey, you got types in my JavaScript!

James Earl Douglas

June 23, 2015


In the next five minutes, I aim to:

Types crypt

The fundamental problem addressed by a type theory is to ensure that programs have meaning.

-- Mark Manasse

Identity crisis

What does this function do?

function foo(x) {
  // implementation hidden


What does this function do?

function foo<A>(x: A): A {
  // implementation hidden

Possibilities Possibility

There's only one possible implementation*: identity.

* If we ignore null and undefined.

Numeric product?

var z = multiply(6, 7);

What is z?

╯°□°)╯︵ ┻━┻

Numeric product...

var z: number = multiply(6, 7);

Now what is z?

┬─┬ノ( º _ ºノ)

Numeric product!

interface Prod<A> {
  product(x: A, y: A): A;

function product<A>(p: Prod<A>): (x: A, y: A) => A {
  return p.product;

var numberProd: Prod<number> = {
  product: (x: number, y: number) => { return x * y },
var multiply: (x: number, y: number) => number = product(numberProd);


It's catchy

Web browsers don't know what TypeScript is. They need JavaScript.

$ tsc multiply.ts




Software maintenance

Types and parametricity