5 Things We Love About TypeScript

When you work in the software development industry, your goal is to always optimize your coding process. At Share IT, we tend to work smart: if there is a way to simplify how we build amazing apps and spot errors and bugs early on, while also boosting performance and reducing the time-to-market - be sure we’ll be using it.

So, what’s on today’s menu on Share IT’s blog, you may be wondering? We’d like to talk about TypeScript, its benefits, and how we use it.

TypeScript is getting increasingly popular in front-end development and many argue that this is how JavaScript should have been built by default. According to StackOverflow's survey from 2019, TypeScript is in the top three favorite languages, right behind Python and Rust. If you take a look at TypeScript at Github, you’ll see that it has over 60.2K stars.

There are some pretty solid reasons why TypeScript is so widely loved and used. But let’s start from the beginning.

What is TypeScript?

text

To be more precise, TypeScript is a superset of the JavaScript programming language that enables strong static typing. This means TypeScript is completely compatible with JS and all its future additions. You can easily take your current .js file, change the extension to .ts and enjoy working with TypeScript.

TypeScript comes in handy when developing larger applications for both client and server side. As a matter of fact, it was created with large-scale applications in mind because JavaScript code was too complex and slowed down the development process significantly. There was an obvious need for a custom tool that would add types to the existing language and help with fixing bugs even before developers run their codes.

Now, let’s take a closer look at the TypeScript benefits.

1. Faster Implementation

When it comes to working with dynamically typed languages like JavaScript, Python, PHP, and Ruby, you can’t just jump in a new project with both feet and start writing code immediately. There’s a certain amount of prep work that needs to come first.

For instance, if you’re working on a basic function code in, let’s say, JavaScript, you need to understand what arguments it accepts, what type of external data it needs, and how these two elements influence the return value you’re looking to produce.

This type of info is often difficult to acquire at first glance. There are many different scenarios that you need to have in mind while trying to get to the bottom of things. Let’s say you need to understand the type of argument you’re dealing with. To figure this out, one of the following steps is required:

  • Running the script into the browser
  • Reading the log
  • Figuring out where the function is supposed to be used
  • Interviewing the colleague who previously worked on the code that has been assigned to you now

As an experienced engineer, you’re aware how much valuable time gets wasted on collecting the necessary information for getting involved with a specific piece of code that is written in JavaScript.

Statically typed languages like TypeScript sing a different song. They don’t make you go through all these loops to enable you to start working on a new project. Your IDE and compiler immediately provide you with all the info you need to start with a new project.

With TypeScript, the days of going through entire bases of code are nothing more than an ugly memory. You no longer have to bug your colleagues with questions, or risk having bugs on production. Which leads us to the next reason why we love TypeScript.

2. Less Bugs

text

Postmortem analysis such as this one from AirBnb, show that up to 40% of bugs are preventable thanks to TypeScript. Some developers estimate that this number is even higher and goes up to 50%.

You can think of TypeScript as an ally that monitors and validates every line of code you write. It prevents errors that might cause bigger issues afterwards. Because developers are only humans, it is almost inevitable to misspell something or use a non-standard error object.

With a type checker, everything gets a lot easier. You know how built in spell checker in MS Word or Google Docs works? When you misspell something, the program underlines the word to signal the mistake. TypeScript compile time checking uses a similar way to point out the error.

In a nutshell, the code is overall more predictable and easier to debug when necessary.

3. Intelligent Code Completion

TypeScript adds a turbo mode to your well-oiled development machinery by catching errors and providing fixes before you even run your code. In addition to that, it also plays well with IntelliSense.

IntelliSense is a neat tool for TypeScript available in Visual Studio. It offers intelligent code suggestions directly in your IDE while writing tests. The IntelliSense suggestion comes in the form of a popup. While you’re writing code, a small window will appear on top of your line, where you can see the command definition, an example of the code you need, and a link to the full documentation page where you can acquire more information.

The tool comes with a variety of valuable code editing features that can assist you in lots of different ways. IntelliSense can autofill your line of code, offer hints, and assist you by offering valuable info on specific parts of your code creation process.

4. Mild Learning Curve

text

In fact, if you’re someone who has already used strongly-typed language, you won’t need more than a couple of hours to really get into the hang of TypeScript. The great thing about it is that it’s not a binary choice: you can use both or utilize TypeScript for specific files that need checking before converting the codebase in its entirety.

5. Well Documented, Evolves with Standards

Last, but not least, TypeScript is well documented and it continuously evolves. The language has been around for eight years, but it has come a long way since it first emerged all thanks to its ever-growing community.

There is a community project called Definitely Typed that provides type definitions for existing JS libraries, editor tools are being refurbished and developed, and more importantly - JavaScript itself is advancing thanks to contributions from all sides. There is also a rather active community on StackOverflow, TypeScript Community Chat, Twitter page, and an official blog; not to mention there are over 8K forks of the project on GitHub.

Since it is modern and well maintained, TypeScript offers a great environment for innovation. Where does your business fall into? Are you looking to build something amazing? Contact Share IT today to discuss your project.