What is it?
It’s Typed-JavaScript. Javscript doesn’t have types, remember?
So you can do ridiculous things like:

var a = 2;
if( randomFunctionIsTrue() ) a = "2";
console.log( a+2 );

Sometimes, this might produce 4 and sometimes it produces “22”. Who knows.

So this is TypeScript

let a: number = 2;
a = "2" // throws compile time error

TypeScript prevents you from doing stupid stuff.

Notice I said TypeScript throws compile time error. TypeScript files (which end in .ts) compiles to .js files.

In the end, TypeScript is just another syntax for javascript and it creates javascript and runs anywhere that javascript can (frontend, backend, standalone).

But wait, there’s more
You may know that you can write classes in javascript, but they don’t look like classes. That’s because they’re functions. With TypeScript, you can write classes and interfaces that actually look like classes and interfaces.

interface Animal {

class Dog implements Animal {

This is not Java. This is TypeScript.

Why use it?
If you’re familiar with Java, you’ll adapt to TypeScript easily.

Because it’s typed, you catch errors early on in compile time, rather than at some arbitrary time during a production run.

Because it’s typed, IDE’s can leverage the compiler hints to give you heads up when there are potential errors. Think the power of Eclipse on java, applied to javascript.

It does everything javascript can because it compiles to javascript. This is just like scala compiling to java bytecode.

You can download a Starter kit example that shows a few interfaces and classes that performs a http request and mysql insert.

Tagged ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: