Why use Typescript ?

Introduction

When I was using JavaScript , there is an inside joke in our team if you don't know coding then you need to use typescript . As Typescript provides you the types that make you write better code with less mistakes before compilation. 

It's all good using typescript but seriously why even barely use typescript for just types , if you know what you are coding , and know all you variables because you give them good naming that make you help understand the code of which is used for.  

Obviously , if you write exactly you wanted and you are a solo developer without any team or any interference, why even bare learning types ?

Why even bare learning typescript ?

Correct question and on point ! But do you know  when you write code on Friday with the strategy you made and when you come again on Monday  , writing the code with the exact same strategy as Friday is not possible and  you can make mistakes . You know , time are bad sometimes and you can't remember the code forever so you can mistakes which later can result in increase of time in debugging. 

Sometimes you know people are in big hurry and in rush mistakes are obvious , that's why we use IDE that gives us proper suggestion while writing code and highlights the code instead of notepad because chances of doing mistake is higher in notepad.

In this case , Typescript comes to rescue with its types and special features like interfaces , generics , tuples etc. 

Typescript has static typing therefore you can't change once it's defined and it will show the error. JavaScript has dynamic typing therefore  you can change the type.

For example, you define a variable in string and later you assigned it to boolean , in this case typescript gives you the error that you can't assign Boolean value to string variable but in JavaScript you can change it to boolean and it will show no error.

Benefits of Typescript

1. Improves code quality

Typescript make the code look more organized and readable as all types are inferenced and there is no chance of mistake with the static typing . One of its main benefits is it does the automated testing before compiling the code which make the code error free before it reaches the production mode

2. Smooth Refactoring

When refactor the code sometimes you change the props and miss the props when changing the code , in this case typescript provides you all the things which is needed by the component when doing the refactoring because refactor the large code is hard and increases the debugging time . Typescript ensures the smooth refactoring of code.

3. Reduced Debugging time

When writing code in typescript , it checks the code before compilation which later helps in debugging and reduce the debugging time.

4. Type safety

Typescript provides you the static types and type inference which provides you the type safety and throw error if you try to change the type once it is defined which helps in avoiding mistakes and better code maintability

5. Better IDE support

IDE provides the better support to typescript , most popular VS code helps with refactoring , coding issues and better types by extensions and ES lint which helps to write code in typescript . It is also supported by other linters and development tools.

6. Better Collaboration

Many companies have JavaScript projects which is hard to maintain and working in the large codebases provides the same issues like type checking , giving wrong type , calling wrong parameter of function etc. With typescript we can collaborate better as it provides all the component needs and third party  requirements or any function which is made by different person ,it can show you the requirements of the particular code.

7. Long term maintenance

Typescript has large community and it is increasing day by day because of its benefits and gives better user experience with JavaScript and react . Is is compatible with the latest javascript and react updates which ensures the longer run of typescript language.

Conclusion

Typescript is a language which is used in alternative of javascript (called superset of javascript) that runs the automated test without doing the manual checking.

It saves the times of manual checking of code bases and prevents you breaking the large codebases with the simple mistakes and also helps in debugging the code as it checks the code before the compilation or runtime .

With the result of its evolving community with the latest javascript and react features , one should you typescript for better maintainability of code , smooth refactoring and writing organized code which is needed for large codebases when you work with so many peoples in real time.

Than you for reading :)
 














Comments

Popular posts from this blog

Learn React Router v6 ( Part - 2)

What is Single Page Application Routing ?