Pros and Cons of Using TypeScript with React
Bunlong
React Patterns Team#
ProsWe have a positive experience with TypeScript. Let we give you an example of how TypeScript is very beneficial in a big project.
For example you have a function called function example(param1, param2)
.
param1
should be a string and param2
should be an object. When you write this function in JS, you can't define the type and shape of your params. You can pass the wrong variables to this function.
But with TypeScript, you can define the type and shape of the object. So you can't pass the wrong variable, TypeScript will highlight the error before you recognize what is wrong.
#
ConsYou have to take time to write the interface, it's time-consuming but worth it.
Some libraries don't fully support TypeScript even a popular library like styled-components still has trouble with TypeScript. You find yourself have to put comment // @ts-ignore
in components made by styled-components.