Demystifying TypeScript

Lighting Edition

NDC Micro, March 2018

@kamranayub

Fact

Writing large javascript apps is hard

The mystical typescript

Demystified

myth #1

"TypeScript is not interoperable with JavaScript"

aka

"I have to rewrite my JavaScript codebase"

What language is this?

var Point = function (x, y) { 
	this.x = x; 
	this.y = y; 
};
Point.prototype.distance = function (other) {
	other = other || new Point(0.0, 0.0);
	return Math.sqrt(
		Math.pow(this.x - other.x, 2) + 
		Math.pow(this.y - other.y, 2));
};

var p1 = new Point(5, 6);
var p2 = new Point(1, 1);

// Calculate distance between two points
console.log("Distance between", p1, p2, "is", p1.distance(p2));

It's just JavaScript!

And it's also TypeScript!

All valid javascript

is valid typescript

Facts

  • TypeScript compiles into plain old JavaScript
  • Static typing is totally optional, but encouraged
  • There is no extra overhead because TypeScript does not run in the browser

You can work with existing js libs

myth #1

"TypeScript is not interoperable with JavaScript"

TypeScript is a typed superset of JavaScript that compiles down to plain, human-readable JavaScript

myth #2

"I have to learn a whole new language"

aka

"I have re-learn JavaScript, my existing skills are useless"