DEV Community

Michael Caveney
Michael Caveney

Posted on

Learning TypeScript, Part One: What Is TypeScript and Why Should I Care?

I'm currently refreshing my TypeScript knowledge and learning how to comprehensively apply it to React, so you all get to learn along with me! Today, we're looking into the basic "what" and "why" of TypeScript.

What Is TypeScript?

TypeScript is a super-set of JavaScript that enables developers to set much more explicit types on values than vanilla JS. This extends beyond primitive values to objects, arrays, and some custom types. If you've spent time with Java or C#, the syntax will feel familiar to you. It is intended to point out and prevent errors at various stages of development, and make code more readable.

Why Should I Care?

One of the features that make it easier to get started with JavaScript is that it's a loosely-typed language, meaning that it infers what type a value is from the type of data it contains. This makes initially learning the language quicker than it would be with a strongly-typed language like Java, but there are some .......oddities. And those oddities can cause problems when they collide with our very human, frequently error-prone brains.

To paraphrase Kyle Simpson, bugs live in the space that is created by the distance between how we think JavaScript works, and JavaScript actually works. One way to close that gap is to comprehensively master how type coercion works in JavaScript, and avoid using certain edge-case values that will cause errors. This way is a LOT of work, that may or may not be worth it to you. Another way is using a type system like TypeScript or Flow to add more type safety to you programs.

Top comments (2)

bbarbour profile image
Brian Barbour

I haven't used Typescript, but if I were to ever use it, it would be for one other HUGE advantage--the fact that it transpiles down to ES5 Javascript for you. Kind of an alternative to running Babel, from what I understand.

dylanesque profile image
Michael Caveney

This is a very good point! Babel is definitely one of the major dependencies of TypeScript!