10 reasons why you should use Typescript
TypeScript is an open-source language which builds on JavaScript, one of the world’s most used tools, by adding static type definitions. Types provide a way to describe the shape of an object, providing better documentation, and allowing TypeScript to validate that your code is working correctly.
Why should you use Typescript?
Simple. It solves your problem. Let's see.
- Type checking: This is why typescript really exists. It adds type checking over javascript. It stops you to write stupid code.
Let's see an example:
1const addNums = (a, b) =\u003e {2return a + b3}
a
and b
should be numbers. But you stupidly pass strings.
1addNums('1', '2')
output:
1'12'
We don't want this to happen. It was a stupid example. But if you are working on a bigger project, this kind of bug can happen easily. You waste hours and hours to fix the code.
This is where typescript rescues us with type checking.
1const addNums = (a: number, b: number) = {2return a + b3}
Now if you pass string it will give you an error so that you can fix it.
Gives error at compile time instead of runtime: Instead of your code giving the error at code run time, typescript will throw you compile error.
Object oriented programming: Typescript allow you to use object-oriented programming concepts very easily. Like class, interface, inheritance, and so on.
Predictable Code: If you have type checking, then you know where to put what type of data. And which code will return which type of output. You can predict the code and it is very important
Great Intellisense: You will have far better IntelliSense with Typescript than JavaScript. If you don't believe me, try it out.
Write Next-generation code: Typescript allow you to write next generation code. It will compile down your code to older versions so that your code stays compatible with older browsers and javascript runtime.
Absolute import and alias: You can use absolute import and import aliases with typescript. They are super helpful. In case if you don't understand the absolute import.
Easy to understand: Typescript makes your code a lot easier to read and understand. Because you know what variable is which type and where to use what.
Support with most libraries: Most of the third-party libraries has typescript.
Great community: Typescript has a huge community. It is so much popular that most developer uses typescript over JavaScript.
and the list goes on and on........
There are a lot more things that are available on the typescript. But I believe they are enough to convince you to use typescript.
So,
Will you use Typescript after reading this blog?
Also if you use typescript what feature do you like most about it?
Please let me know. I would love to hear from you.
Shameless Plug
I have made an Xbox landing page clone with React and Styled components. I hope you will enjoy it. Please consider like this video and subscribe to my channel.
That's it for this blog. I have tried to explain things simply. If you get stuck, you can ask me questions.
Contacts
- Email: thatanjan@gmail.com
- LinkedIn: @thatanjan
- Portfolio: anjan
- Github: @thatanjan
- Instagram : @thatanjan
- Twitter: @thatanjan
Blogs you might want to read:
- Eslint, prettier setup with TypeScript and react
- What is Client-Side Rendering?
- What is Server Side Rendering?
- Everything you need to know about tree data structure
- 13 reasons why you should use Nextjs
- Beginners guide to quantum computers
Videos might you might want to watch: