DEV Community

Discussion on: React PropTypes vs Typescript! Any experience?

Collapse
 
dubyabrian profile image
W. Brian Gourlie

If you use TypeScript, there's absolutely no need for prop types as TypeScript is in charge of type checking.

This isn't entirely true. There are a number of situations where TypeScript's static typing won't save you, the obvious scenario being a package written in TypeScript that is consumed in javascript.

There are other scenarios that I've run into, in particular when using something like Redux to bind your properties. Often times the ambient type declarations aren't perfect and unexpected data can flow through. PropTypes has helped me debug these scenarios.

Collapse
 
nickytonline profile image
Nick Taylor

For your first point, my assumption was that the project was built in TypeScript. If it wasnt though, you are correct, a package built with TypeScript consumed by a plain JavaScript app would not help. On a side note, an editor like VS Code downloads types for packages in the background to provide Intellisense in a JS project.

For your second point, I haven't run into this issue with TS and React. Do you have a sample project demonstrating this?