facebook / prop-types

Runtime type checking for React props and similar objects
MIT License
4.48k stars 356 forks source link

Should the error message for directly calling validator functions be removed in production mode? #197

Open markusenglund opened 6 years ago

markusenglund commented 6 years ago

Currently, this package will throw an error when validator functions are called directly in both dev and production mode. Calling validator functions directly was previously supported when PropTypes was bundled with React in < react@15.4, so it's understandable that you want to warn developers who are changing to the prop-types package. However, it's been well over a year since directly calling validator functions was deprecated, so the utility of the error message is now considerably less.

My question is: Isn't it enough to warn developers only in dev mode?

By removing the error message from production mode, you could save around 160 bytes gzipped from the final production bundle. That's a paltry number, but since prop-types is bundled in basically every react app in existence it does add up.

ljharb commented 5 years ago

You can use checkPropTypes to avoid that error.

Either way, the amount of time that has passed, when any version can be installed at any time, isn’t really a factor.

markusenglund commented 5 years ago

What I tried to get across in my original comment was that by removing the error from prod mode we could save 160 bytes from basically every React site in existence which would be great. I guess I don’t get why throwing this error in production is any better than just returning undefined as is done when the package is used correctly. As I understand it, the message is only useful for a hypothetical project that

Maybe I misunderstood something, but to me this error seems pretty useless. Removing it would technically be a breaking change though so not something you would want to do unless there is ever a 16.0 release.