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.