TypeScript provides all the power of JavaScript and all the strong-typing of C#

Nick Hodges
Sep 8 · 5 min read
Photo by Arnold Francisca on Unsplash

There’s a lot of buzz about TypeScript. Some JavaScript purists seem to resist it. Newcomers from other languages, like Java and C#, seem to love it. No matter what the view, it’s interesting — in at least 12 different ways.

TypeScript from an Angular Project in Visual Studio Code (by the author)

1. TypeScript Is a Superset of JavaScript

One of the selling points of TypeScript is that it’s a superset of JavaScript — meaning that all JavaScript is valid TypeScript. This fact allows you to take a *.js file and switch it to a *.ts file and use it as-is in TypeScript. This also lets you convert to TypeScript gradually. You can start with pure JavaScript and progressively migrate your code to use the features of TypeScript.

That’s the theory anyway. In reality, it’s like 99.9% true. There’s some debate about whether the statement is 100% accurate, but the bottom line is that you can compile all JavaScript with the TypeScript compiler. The compiler may complain about some minor details, but it will compile and emit the code.


2. TypeScript Compiles to Whatever Version of JavaScript You Want

TypeScript compiles (or more precisely, transpiles) to JavaScript. The cool part is that you can choose the version of JavaScript that the TypeScript compiler will produce. You can select any version of JavaScript via the --target compiler option that you want, starting with the ECMAScript 3 standard. You can even choose ESNext, which will target the latest proposed language features from the ECMAScript committee.

The advantage here is that you can use all the modern language features of TypeScript in your applications, but you can still target and support older browsers. That’s pretty cool.


3. TypeScript Is Popular

Many, many developers are taking advantage of TypeScript’s features, including Angular developers and lots of folks that use StackOverflow. TypeScript cracked the Top 10 in the most recent StackOverflow Developer Survey — up from the previous year. It’s now the seventh-most used language on Github. TypeScript is widely used, growing, and here to stay.


4. TypeScript Is Open-Source

The TypeScript compiler and accompanying code is a project on GitHub. There are over 7,300 forks of the project. Over 53,000 developers have starred it, and over 1.4 million projects use it. (All of that lends credence to the above point about popularity.) It’s released under the Apache 2.0 License.

Want to see exactly how the compiler works? Want to fork the project and fix a bug? You can. Pull-requests are open. It’s as open-source as it gets.

And because of all the community support, TypeScript moves quickly to support all the latest language features and trends.


5. TypeScript Is Led by Anders Hejlsberg and Backed by Microsoft

For folks like me that have been around a while, this may be the most fantastic bullet point of all. Microsoft has embraced the open-source culture, and TypeScript is just one manifestation of that trend.

And for an old Delphi developer like me, it’s great to see Anders Hejlsberg working on another fun language project. (Anders was the original designer of Turbo Pascal and Delphi). He’s quite well known for several large projects, including the C# language and much of the early .Net Framework. Anders leads the TypeScript project and is an active part of the open-source process. It’s fun to see him commenting and approving pull requests and such.


6. TypeScript Enables JavaScript to Scale

JavaScript has outgrown its humble beginnings. Originally meant to be a simple scripting language to help make web pages look better, it became the lingua franca of the web. Now, it’s used to build large scale web applications and even server-side applications via node.js.

However, JavaScript’s early incarnations lacked the things needed to build enterprise-level applications like objects, modules, components, and other language features that enable developers to design and build such projects properly. One of the main purposes of TypeScript is to provide those features, enabling the easier design and development of complex applications.


7. TypeScript Is Strongly Typed

TypeScript provides types and a compiler that enforces those types. Typing allows you to keep everything where it should be and prevents things from getting improperly assigned. No more chasing down bugs from weakly-typed assignments. No more passing improperly typed parameters. TypeScript can provide coding-time and compile-time error checking. The debate about strong vs. weak typing is real, but at least with TypeScript, you can choose.


8. TypeScript Provides a Complete Tooling Experience

Another strong reason that TypeScript was created was to give the powerful code-time experience that typing allows. Strong typing allows code editors to easily provide IntelliSense-like features, refactoring, and other code-based features. All that tooling means that the editor can immediately point out coding errors to you, and they can even provide fixes for those problems. All these editor features can drastically improve coding efficiency and the cleanness of your code.


9. TypeScript Provides All the Modern Language Features

TypeScript has all the modern language features like generics, enums, OOP, interfaces, conditional types, decorators, modules, etc. And it allows you to use these language features all while supporting older browsers. Sure, the current version of ECMAScript has most if not all of the same features as TypeScript, but TypeScript allows you to be flexible in what level of JavaScript you support all while still allowing the use of all the modern language features.


10. TypeScript Is Battle-Tested

TypeScript has proven itself worthy in any number of substantial projects. Of course, the TypeScript compiler itself is written in TypeScript. The web framework Angular is written in TypeScript. Many large, public-facing Google properties are written in Angular (Google sponsors the open-source Angular project). Visual Studio Code is written in TypeScript. So is Slack. TypeScript is up to the challenge.


11. TypeScript Is Free to Innovate

While TypeScript closely supports the latest ECMAScript standards, it remains free to innovate and add new and interesting language features that you can use today. TypeScript is modern, current JavaScript with the ability to add features as they’re conceived. And remember, it all compiles down to ECMAScript3 if you want it to.


12. TypeScript Is Easy for C# and Java Developers to Understand

Dynamically-typed languages like JavaScript can sometimes be a difficult transition for statically-typed language users to understand. TypeScript is heavily inspired by C#, and thus it’s a much easier step to take for C# and Java developers that want to start working on the front end.


Conclusion

TypeScript is an interesting and exciting language. It does everything that JavaScript does and more. It’s gaining in both popularity and capability. More and more front end development frameworks, as well as Node, are supporting it. Overall, it’s worth a look for your next project.

Better Programming

Advice for programmers.

Nick Hodges

Written by

I write about pretty much whatever I feel like writing about. Like @codinghorror, I am an indoor enthusiast.

Better Programming

Advice for programmers.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade