TypeScript: The DX of editing TypeScript

I think the key aspect of using TypeScript is in the developer’s experience (DX) that it gives us.

The end result of TypeScript will be JavaScript without types.

Because the browser cannot understand types (yet?), they are stripped away once the program is compiled to JS.

So what are they for?

They are for the editing experience.

While working on your app in the editor, the editor will be able to automatically understand if the program has an error, much more than what it can do with JavaScript.

So you can catch possible sources of problems before even running your code.

And, as an additional benefit, when you’re writing code, the editor (VS Code for example, but others too if set up for this) will give you hints about the types, the variables and parameters that you should write.

And you commonly get this “for free” when using libraries that provide types.

TypeScript is not the only way to do this.

In plain JavaScript we have JSDoc, and many libraries prefer using this.

What matters is that our life is easier either way.

You can decide to use JavaScript, but the benefits using other libraries are the same.

And if you choose to use TypeScript, you can benefit from having types in your code, something that I think makes sense when your app grows larger, and you are working with a team of people.

When you can’t keep all the code in your head any more.

TypeScript gives you more structure and things to worry about. It forces you to think about types, and sometimes for simple projects you might find it gets in the way.

JavaScript is great because it’s dynamic and gives you a lot of freedom. But freedom can be a double-edged sword, because it’s a bit too permissive.

But we’re lucky enough to be able to choose between those 2 “versions” of JavaScript. You can pick the one you like the most, depending on the situation you’re facing.

Lessons in this unit:

0: Introduction
1: Your first TypeScript program
2: Types
3: Typing functions
4: The editor helps you with type errors
5: Running TypeScript code
6: Valid types
7: Type aliases and interfaces
8: Union types
9: Typing arrays with generics
10: ▶︎ The DX of editing TypeScript
11: There's more...
Want to learn more? Check out our courses