TLDR: Type safety, productivity, intellisense, and debugging.
In continuing with my recent trend of using TypeScript, I wanted to illustrate how to create functions and variables in TypeScript, because this initially threw me into a loop. The code for this example can be found here.
That can save you a lot of trouble in the end. Even so, I can accidentally pass in the wrong type, and the debugger won’t tell me. But with TypeScript, I don’t have that issue!
Here is an actual template that I’m using to generate some HTML for a container with biographical information about evangelists:
Here is that same code, but with TypeScript:
Now, I am explicitly clear as to what I’m expecting for each parameter. If another programmer was to come by and pass in the wrong type, the script wouldn’t compile, and I’d receive an error on that line.
With TypeScript though, you have intellisense through type definitions, which I wrote about in-depth here.
David Catuhe, one of the engineers behind the open source WebGL project, BabylonJS, had a great blog post two years ago about why they made the switch to TypeScript as well.