DEV Community

Fathe Karim
Fathe Karim

Posted on

React typescript

Recently I am working on a large-scale project using MERN and typescript. We are using typescript because we can handle most of the errors easily before publishing the project at the production level. As far I understood It is a strict superset of JavaScript that adds optional static typing and class-based, object-oriented programming to the language. Sometimes it is very painful to set the types for values. Also sometimes it is hard to understand what type would be for the value.
If the state will be a string then we need to set the typed string and if the state is an array string we need to type like this way string[]. All element default value is any which is not recommended to use, otherwise, we will face some error in the frontend if the data pass wrong data. There is a file called tsconfig.json in each project's root folder that contains instructions for TypeScript. It loads the tsconfig.json file and uses its settings to build the project when it finds it.

As I am using react. I think TypeScript and React are a perfect fit. I am enjoying combining both technologies together to get a huge productivity boost when writing my applications!

There are some pros and cons to typescript which is:
We will get an instant error if we set any wrong property so that we can fix it instantly.
Readable, easily understandable code
Better support for JSX

Sometimes we need to use NPM packages, if the package does not have any typescript version then we can not use it.

Top comments (0)