Type it out...
Tags: typescript, programming, webdev, beginners
Published: 2023-06-01 02:51:53


### What is TypeScript, why would you use it, and when would you use it?

Jump to section

- [What is it?](#section-1)

- [Why would you use it](#section-2)

- [When you would use it](#section-3)

- [Benefits Recap](#section-4)

- [Resources for Typescript](#section-5)

**TypeScript** was one of those things that I was always reading/hearing about, but didn't look into myself yet as I was learning different things already. The buzz around **TypeScript** is real, which breeds a question: is it **worth** checking out?

#### What is TypeScript?
<a id="section-1"></a>

According to the [TypeScript documentation](https://www.typescriptlang.org/), **TypeScript** is a strongly typed programming language that builds on JavaScript, giving you **better tooling** at any scale.

What does that mean in lighter terms? Basically, you can cover your own back and prevent errors from popping up down the road where you would not expect them. The TypeScript tooling handles the type syntax as well as **type inference** - essentially, TypeScript pairs with and understands the JavaScript code being written and can **infer** types from syntax that lack it. **You do not have to give a type everything**

A type is simply a specification for a type of given data, I.E. string, number, boolean, or ect.

![JavaScript logo changing to TypeScript Logo with an arrow pointing from left to right towards the TypeScript logo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s0konapf7spc3u66rvbj.png)

#### Why use TypeScript?
<a id="section-2"></a>

As I mentioned before, one benefit of TypeScript is **error prevention**. This is always an important issue, especially if you are unsure if the _scale_ that the codebase you are working with is going to **expand/change**. You might save your future self some headache by leveraging **TypeScript**.

![Clip art image of someone with a headache at work at a computer](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ym43zcc8kzfsnbeqwxb5.png)

**Readability** of code is a huge deal that is touched on quite a bit. No one wants to have to read through a bunch of _complex_ _code_ with unique variable names and no comments. Well, to throw a little extra readability into the mix, TypeScript can help you understand what to **expect** with your codebase. With the types provided for you, it becomes easier to infer what the code is doing/performing.
Example:

```
interface Person {
name: string,
age: number
}
const person: Person = {
name: "Clif",
age: 24
}
```
I created the _interface_ of Person and declared that the new const variable of person was going to be of that type: Person. With that being said, the const variable has properties that are respectively a string and a number. (Any other data form will throw a **type Error**)

#### When would you use TypeScript?
<a id="section-3"></a>

Some would argue whether it is right or wrong to always use TypeScript, I don't think there is a right or wrong answer there. TypeScript is definitely a handy tool, but you can also get by without it. Essentially, I would say that it is a good idea to use **TypeScript** if you are **unsure** of the direction/scale of the work that you are doing. **It is easier to start with it than to go back and add it down the road.** 

As mentioned earlier, there are many benefits with TypeScript when it comes to working with large teams/organizations, so there is a very good use case there. Readability, error prevention, and overall code quality are all strong factors that TypeScript can offer.

![Team all putting their hands into the middle of a huddle](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3vajzdrjb36me0ykl3nw.jpg)
#### Benefits Recap
<a id="section-4"></a>

1. Error Prevention

2. Type Inference

3. Code Quality/Scalability

4. Code Readability

5. Overall Productivity 
 

#### Resources for learning TypeScript
<a id="section-5"></a>

- [TypeScript Docs](https://www.typescriptlang.org/docs/)

- [Front End Happy Hour Podcast](https://www.frontendhappyhour.com/episodes/typescript-migration-strict-type-of-cocktails/)

- [Stack Overflow](https://stackoverflow.blog/2021/05/05/getting-started-with-typescript/)