Better JavaScript programming with TypeScript

TypeScript helps you write better JavaScript, tame large JavaScript projects, and prepare for ECMAScript 6 -- and getting started couldn't be easier

Become An Insider

Sign up now and get FREE access to hundreds of Insider articles, guides, reviews, interviews, blogs, and other premium content. Learn more.

If there’s a lingua franca of the modern development world, it’s JavaScript. Netscape’s browser scripting language has come a long way in almost 20 years and now can be found almost everywhere. It’s at the heart of much of our development tooling, and with server-side implementations like Node.js, it’s also driving much of the move to microservices. JavaScript is even at the heart of much of Microsoft’s development technologies. Want to extend Microsoft Office? You’re using JavaScript. Want to write a Windows 10 UI? You’re using JavaScript.

But JavaScript is not perfect, especially when you’re building a large-scale Web application that includes a lot of client code. That’s where TypeScript comes in. TypeScript is a superset of JavaScript that adds features intended for the upcoming ECMAScript 6, and it can be transcompiled into JavaScript for use in current browsers -- and on Node.js.

TypeScript was designed by a team at Microsoft led by Anders Hjelsberg (perhaps best known for his work on Turbo Pascal, Delphi, and C#). The Microsoft team has designed TypeScript to use a compiler that’s written in JavaScript. You write code in TypeScript and pass it through the compiler. The resulting JavaScript either runs server side or can be called on the client from your HTML.

TypeScript adds a lot of ECMAScript 6 features to JavaScript, including classes and modules, and the team intends to bring the two language dialects closer together as the ECMAScript 6 standard approaches ratification. It’s a sensible approach. You can use TypeScript to get your code ready for ECMAScript 6, while taking advantage of TypeScript’s static typing to make your code safer and more secure.

If you’ve used languages like C or Fortran, you’ll be familiar with static typing, which lets you declare types for variables to ensure, for example, A is always an integer and C is always a string. While TypeScript’s type safety isn’t as comprehensive as, say, Fortran’s, the ability to define number, string, and Boolean types can significantly help with debugging code. There’s also the option of letting TypeScript infer types, reducing the risk of errors when, for example, you assign an object to a string without an appropriate conversion. If your code is adding two numbers together, TypeScript will assume the result is always a number.

To continue reading this article register now