Stop coding in Javascript! Use Typescript instead

Stop coding in Javascript! Use Typescript instead

Introduction

Recently, I created a Twitter thread about why Typescript should be your preferred language for web development. These thoughts were based on the experiences I had while learning Javascript and how TS helped me overcome them, during the last 2 years of my Web Development journey.

Here I present the key take-ways from that thread:

💪 Typescript is Javascript, but better

TS is an open-source language that adds static typing to javascript. If you already know/ are learning javascript, TS is a big upgrade that's easy to learn and get the hang of. Once you start using it, it will become a powerful tool in your arsenal!

🙌 Compile-time safety for the win

Ever had a situation where a function accidentally received a null when it was expecting a number? With static types, you can rest assured that the input and output of your functions will always be the expected type.

1*_6BV2ztpIIS0ZqUPR3vFTg.png

1*YwS3tSFsQRv8SPfiHEw0eA.png

The same function with(bottom) and without(top) Typescript

🧑‍💻 Interfaces for improved development

You can harness the power of interfaces to make your classes and objects more secure than ever! Interfaces make your life easier by always reminding you of common functions that you may have missed during class definition.

1*mDlhrspKdUCKj8P--fVueg.png

💡 Your IDE remembers

When your code grows large, it's easy to forget what function is expecting what arguments. This can lead to a lot of back and forth between files, which takes time and patience. With typescript and the right extensions, your IDE tracks it for you!

1*c_YkjxVtNkRkzuUZd9oRNQ.jpeg

↔️ Javascript is also typescript

Do you want to start using typescript quickly? It's easy! Since typescript is a superset of Javascript, you can technically get started by renaming your .js files to .ts and adding type annotations wherever prompted. Just make sure you have the typescript compiler installed!

🔍 Improved Readability

Typescript when used correctly, also serves as a form of basic documentation. This is extremely critical when your code is read by other developers in the future. Type annotations allow others to know exactly what to input to provide to your functions and what to expect in return.

💭 Final thoughts

With enough practice, Typescript can save you a lot of time and frustration that you would otherwise have spent looking for semantic/runtime errors. A lot of IDEs have great support for TS and can make your development process more enjoyable than ever!

Did I miss out on any points?

Feel free to comment your thoughts about TS below.👇