TypeScript

What is TypeScript and why should you use it?

Mr. Shadrack
4 min readMay 10, 2022

One of the tools that have had a great impact on my productivity is TypeScript. This is interesting because a few years ago, I had no interest in learning it. My first experience with TypeScript came when I started learning angular.

In case you’re not familiar with the word, “type”, it basically tells you the intended use of given data (for example, we have numeric, boolean, or string types).

There are two kinds of typed languages, dynamically typed languages and statically typed languages. With dynamically typed languages, types are not named explicitly in your code but are associated with run-time values. Traditionally, JavaScript is dynamically typed, other examples include, Perl, Python, JavaScript, Ruby, etc. On the other hand, with statically typed languages, you explicitly assign types to variables, properties, function parameters, return values, etc. Example: Java, C++, C, Go, and more.

Developers using JavaScript from other languages used to complain about the lack of strong static types, and that’s where TypeScript fills that gap.

What is TypeScript?

TypeScript is an open-source language managed by Microsoft. It is a superset of JavaScript that has optional typing. It can be considered JavaScript with additional features like strong static typing and object-oriented features.
It is worth mentioning that TypeScript files compile down to regular javascript for browsers to understand. This also means that the final code can run on any environment which supports JavaScript. NB: Browers CAN’T execute TypeScript.
The language is evolving rapidly, and the TypeScript developers’ community continues to grow. TypeScript can be used for frontend Javascript as well as backend with Node.js

Why should you use typescript?

TypeScript overcomes JavaScript’s big issue; which is that a problem can only be detected during runtime in JavaScript. This may result in applications with a lot of bugs being shipped into production. TypeScript is here to solve this problem by checking for any issue at compile time.

Let’s look at some more reasons why you should start using Typescript for your next project.

Cleaner and more Readable Code

With TypeScript, you can write, less error-prone, better, and cleaner code. Defining data models using types and interfaces makes your app's data structure more clean and readable and it also forces you to think about your app’s data structure and make better design decisions.

Great IDE/Text editor Support

Most IDEs/text editors have great support for TypeScript, providing you with better suggestions, IntelliSense, and linting to help you easily spot bugs and be more productive.

TypeScript
JavaScript

Better developer experience

In JavaScript, developers often think about things like, “what type of fields are in this object?”, “what arguments this function accepts?”, “what type of value this function returns and so on. This slows us down as developers. We have to go through multiple files to find out where the value comes from, and what type of parameters can I pass. These problems are solved when you are using TypeScript. One of the main conveniences is that you know not only the name of the variable, but also what kind of data it stores.

let isActive: boolean;

TypeScript is more reliable

In contrast to JavaScript, TypeScript code is more reliable and easier to refactor. This enables developers to spot errors and fix them much more easily. Providing types will help you catch most of the silly errors that can sneak into JavaScript codebases.

An active and constantly growing community

TypeScript is getting more and more popular. It’s used by top tech companies like Microsoft, Google, Airbnb, Shopify, Codecademy, Medium, Adobe, Mozilla, etc. This means you can’t really doubt its scalability.

Check out how often Typescript is downloaded on npm here

From typescript repository

TypeScript also introduced a great deal of syntax taken from object-oriented programming, including but not limited to:

  • interfaces,
  • classes,
  • generics,
  • modules.
  • enumerated types

We can go on and on and talk about more reasons why typescript is the best option for your next project. You should definitely use it. This does not mean Typescript doesn’t have any drawbacks. I will list a few of these drawbacks below.

Cons:

  • More code to write
  • More to learn
  • Required compilation
  • Not true static typing

Conclusion

You can visit the TypeScript Docs to read more.

You can also get started by trying it out at the TypeScript playground

Thanks for reading.

--

--

Mr. Shadrack

Frontend Engineer | JavaScript | React | Angular | TypeScript