React: JavaScript or TypeScript?

Chase Baker

Chase Baker

- Software Engineer

I recently wrote a blog on which state management to go with when starting a React project. Another question is “Which do I choose JavaScript or TypeScript?” So, I decided to write another short blog about the pros and cons of both and what I ended up going with.

I’ll just get right into it!

React with JavaScript

React was originally intended to be used with JavaScript so some purists may want to keep it that way. If you want to use the one that is more widely used than ReactJs would be the choice. Also with it being the most common it will be easier to find more examples online for it.

Pros:

  1. Less Code
  2. Arguably shorter compile time
  3. Reacts standard documentation is JS oriented
  4. Massive support for JavaScript in general
  5. Solid Performance with JavaScript

Cons:

  1. Higher Chance of Production Bugs
  2. Not as simple to read/Messy
  3. Creating Standards for developers can be more challenging
  4. Comes with issues the JavaScript already has
  5. No Intellisense

React with TypeScript

This is a relatively new way of building React apps but is gaining ground. TypeScript in general is becoming more and more popular for front-end web development mostly due to its readability and type checking.

Pros:

  1. Type checking
  2. Cleaner code
  3. Arguably less bugs
  4. Less unit tests
  5. Simpler documentation

Cons:

  1. Longer compile time
  2. More code
  3. Type checking can be annoying hard to manage
  4. Less libraries with type support (Has been getting better with time)
  5. Support is great but not as much as JavaScript

Conclusion:

After all my reading and researching it really turned into an argument of JavaScript vs. TypeScript instead of using React with one or the other. The support seems to be there for both, clearly there is more support and/or uses of ReactJS found online. While both have their advantages and disadvantages my recommendation would be TypeScript.

I think the benefits outweigh the risks, TypeScript has a massive following and seems to be the way the world of front-end development is going. With TypeScript it is easier to catch bugs that could have caused production errors reported by users which is the last thing we as developers want. The code is cleaner and will be easier to scale or change as the project does. I also think newer developers (or new to the team) can adjust to it easily because they will need to follow TypeScripts strict typing laid out by the more seasoned developers.

Well that’s my opinion on the topic and I hope that this blog was helpful in some way. Thanks for reading!

Below are a few of the articles I used to research the topic

For TypeScript:

Advantages of using React with TypeScript

Against TypeScript:

I couldn’t find a ton of reading on this exactly, most of the views I found against it were from stack overflow and/or reddit threads. Here is one article I found against TypeScript.

Don’t use TypeScript for your next project

Helpful Video that simply talks about both React with JavaScript and TypeScript.