TypeScript or PropTypes

ritabradley profile image Rita Bradley ・1 min read

Of course my first post ever after being a member for 3 years will be to ask a (probably) dumb question. If you write React apps with TypeScript, is it even necessary to declare PropTypes? If so, why? If not, why not? I'm really trying to work up the courage to continue learning TypeScript but as I primarily create with React, I have a hard time seeing its usefulness. Please educate me! Much appreciated.


markdown guide

You don't want to have both.

In most apps PropTypes is enough. If you really think about it TypeScript is worth it mostly in critical apps where you have multiple defensive layers against possible mistakes. Another good use for TypeScript is for shared code, such as libraries. For shared component libraries both PropTypes and TypeScript can do the work. But there is also JSDoc which can be used for defining inputs and outputs.

None of the three things mentioned (JSDoc, PropTypes, TypeScript) will help you with runtime issues. They're not part of the code that goes to user's browser. They exist to provide development time warnings and communicate possible values for developers.

TypeScript is of course a trend right now and many places have made use of it which can make it worthwhile to learn. People like TypeScript as it can provide comfort and be helpful especially to people who are joining to an existing code base, or who are at the beginning of their career, or new to JavaScript and come from a statically typed language.


Thank you so much for this explanation. I was aware that neither help during runtime but I never considered why they would be used if it’s not something that’ll affect runtime. I never considered that TypeScript could be beneficial to people coming from a different language. Makes perfect sense.


TypeScript If you want to ship bug free code.