Learning Typescript is the best decision I made as a Frontend Developer

Learning Typescript is the best decision I made as a Frontend Developer

Here's my story of How I started with Typescript...

If you consider Typescript an option for your Projects and are confused about whether you should learn it or not?? So I am going to say a big yes to you. To have a convincing offer I will share my Story on "How I started with Typescript" and My thoughts on it before and after using it.

(You already know my afterthoughts. :p )

MY STORY

1) Setup

So Let me give a quick background about myself. I prefer to call myself a javascript enthusiast. I prefer it over any other language. And this being a primary reason why I learned NodeJS and also for not readily accepting Typescript as an option.

When I got to know about the existence of Typescript, which is acutally a superset of Javascript

My exact reaction was this

tenor.gif

"WHY?? Why do we need a language like Typescript? Who cares about types? I can save whatever I want wherever I want. Why are we planning to remove that freedom from Javascript??"

2) Initial Attempt

But the fame of typescript was rising day by day and it was hard not to listen to it. So I finally decided to give it a try.

tenor1.gif

So I watched a few TS tutorials and didn't find it exciting. But that was not enough for me. I want to know its taste in a complete project. At that time, I already knew ReactJs, and have heard that Angular and Typescript were progressing hand in hand. Angular being an alternative framework, I also wanted to know about it as well. So I decided to learn a bit Angular as well and do a project using Angular and Typescript. And this turned out to be a terrible decision.

3) Experience of Angular & Typescript's Project.

At this point, I already had the basic idea of React and was trying Angular. The wall which arose in from of me was of Angular. It has quite a lot of elements, which were a bit different from the ecosystem of ReactJS. I did complete my project, and the result was I become a bit disinterested in Angular. And my that dislike got attached to Typescript as well.

tenor3.gif

My only mistake was, I tried judging Typescript based on the complexity of Angular considering it as an integral part of Angular and ignoring its independent existence.

Now it had a crystal clear thought. I am going to keep on ignoring Typescript and also will prefer React over Angular.

4) Returning to Typescript

So as I said ignored the use of Typescript and kept moving forward. I did few more projects and learned NodeJS as well. In the meantime, Typescript continued evolving and gain a lot of community support. Again, this thing got my attention. I decided to try it again, but not with Angular this time. So I picked a Node Js and Express project and built it using Typescript this time. I also followed a youtube tutorial to understand the best practices and understand the views of an already Experienced person on it.

I found myself in a different situation. I definitely put some extra effort into setting a typescript environment and defining types, but it was worth it.

I made the following realizations while using Typescript

  • I started to enjoy giving types in my code.
  • It made the process of understanding code flow effortless.
  • No struggle of understanding and checking nested objects.
  • And extensions of VS Code make development much more manageable.

tenor4.gif

The above points are just a few realizations I had while developing code. Other than that, Typescript helped in following ways also:

  • It provided clarity on the purpose of that variable or function.
  • It helped in identifying the null and undefined checks, which most of the developers tend to miss.
  • Error messages were more meaningful now. Telling the more accurate location of the issue and a much detailed reason for that issue
  • It helps to identify type leaks or missing properties, or invalid objects or function calls.

5) After Project Thoughts about Typescript

As a result, the code becomes more strict, more evident, understandable, and informative.

  • The questions I had at the beginning of the story were answered now, I actually started liking them.
  • The beauty of Typescript is, it is strict and flexible at the same time
  • Flexible enough to do all thing that is possible in Javascript
  • Strict with its rule to guide you in what you want. These rules are even configurable, so you will find yourself using only those rules you like in the long run.

Suppose I talk about the perspective of maintainability and understanding the code. The effort gets reduced over there as well.

  • Consider the example where you are developing an application. You halted the development of that app for few days or took few leaves, or planned to refactor your code. In all such scenarios superpower of Typescripts kicks in. Allowing you to do whatever you want does not accept whatever you write,

I was so impressed by it that I decided to try Typescript with React as well. After performing and doing all the setups, I started development in ReactJS + Typescript. After getting some comfort and flow with it. I realized it was super cool. If compared to Prop-types, Typescript turned out to be much better and practical, making me regret not making such a change earlier.

6) Wrap Up

In case you are not able to understand the gist of the Story. Here are some final tips from my side:

  1. Never judge something based on the complexity of another item. In my case, I got so confused with Angular. I never saw the offer of Typescript.

  2. If you are a beginner in Frontend, the recommended option is to stick to javascript only. There's no point in breaking your head with types until you understand the basics of Javascript. Have a good understanding of at least ES6 and then hop into TS train to unleash the beast.

  3. If you are going to try Typescript for the first time, try doing it in a small project. Create anything which you already know about, make some twists in it snd then try it. In this way, you are actually going to see some difference.

  4. If you have a basic understanding of defining variables and types in languages like C++, Java & you are having an open mind. Then Typescript is going to be super simple for you. And if you think it is unnecessarily complex, follow this approach :

    • Create simple programs, any program or script that you can think of. Pick an existing Javascript code (a small one only) and Try converting it into Typescript.
    • Do the previous step 3 to 4 times. And then select any medium complexity project. (While I will recommend a React Project at this point) You might get a chance to create your own types.
    • By the time you complete half of your project, you would have already developed a good amount of understanding to pick things on your own.
    • And if you think the above point steps are too much. Then it would be best if you referred Point-2. Having a basic idea of ES6 is going to play an essential role here.

At last, I want to say that Typescript is the best option for every Javascript Developer. In reality, it is just the addition of a few words to the code and few files in the whole project. But the impact it causes is quite immense.