What is TypeScript? TypeScript Advantages


Angular is a modern framework that is written entirely in TypeScript. And using TypeScript with Angular offers a seamless experience. The Angular documentation not only supports TypeScript as a first-class citizen but uses it as its primary language. TypeScript is the ES6 version of JavaScript plus a few other TypeScript-only features which Angular needs in order to work.

You can write Angular applications in either TypeScript, ES6, or even ES5 JavaScript. But, Angular is actually written in TypeScript. You may see, that most examples on the web are written in TypeScript and most Angular jobs require you to write TypeScript.

TypeScript Advantages

The biggest selling point of TypeScript is tooling. It provides advanced autocompletion, navigation, and refactoring. Having such tools is almost a requirement for large projects. Without them, the fear of changing the code puts the code base in a semi-read-only state and makes large-scale refactorings very risky and costly.

TypeScript is not the only typed language that compiles JavaScript. There are other languages with stronger type systems that in theory can provide absolutely phenomenal tooling. But in practice, most of them do not have anything other than a compiler. This is because building rich dev tools has to be an explicit goal from day one, which it has been for the TypeScript team. That is why they built language services that can be used by editors to provide type checking and autocompletion. If you have wondered why there are so many editors with great TypeScript supports, the answer is the language services.

While TypeScript greatly improves the code editing experience, it makes the dev setup more complex, especially compared to dropping an ES5 script on a page. In addition, you cannot use tools analyzing JavaScript source code (e.g., JSHint), but there are usually adequate replacements.

There are a lot of options available to frontend devs today: ES5, ES6 (Babel), TypeScript, Dart, PureScript, Elm, etc. So why TypeScript?

Each of these options has pros and cons, but I think TypeScript is in a sweet spot that makes it a great choice for most projects. TypeScript takes 95% of the usefulness of a good statically-typed language and brings it to the JavaScript ecosystem. You still feel like you write ES6: you keep using the same standard library, same third-party libraries, same idioms, and many of the same tools (e.g., Chrome dev tools). It gives you a lot without forcing you out of the JavaScript ecosystem.

Leave a reply