Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do we need propTypes with TypeScript?

My new react-native project which is setup now uses typescript. So, is it required to use propTypes for type validations since TS already solves this problem? For me, I think use of propTypes will not add any value with since TS handles the type casting issues. Is it correct or should I use propTypes? If so, what are the advantages?

like image 498
Shashika Avatar asked Oct 28 '25 16:10

Shashika


1 Answers

propTypes is just Reacts form of typechecking, if you are already using a static type-checking library like TypeScript then no, you won't need to use propType validation.

React make it clear in their documentation that propTypes are an option to those who aren't already using a form of type-checking:

As your app grows, you can catch a lot of bugs with typechecking. For some applications, you can use JavaScript extensions like Flow or TypeScript to typecheck your whole application. But even if you don’t use those, React has some built-in typechecking abilities.

like image 93
James Avatar answered Oct 31 '25 08:10

James