Mstar0816 / Portfolio

https://my-portfolio-ten-orpin-68.vercel.app
4 stars 0 forks source link

propTypes #10

Open Mstar0816 opened 7 months ago

Mstar0816 commented 7 months ago

Force ReactJS to throw real errors when propTypes validation fails?

Mstar0816 commented 7 months ago

At present, if propType validation fails, ReactJS uses console.warn to emit a warning. I really, really want a real error in dev mode, so it can fail our continuous integration build, instead of just printing a message that might be lost in the shuffle.

Mstar0816 commented 7 months ago

There's already been discussion of this, e.g. in this feature request, and this related question describes the current behavior as expected. That's fine, but I personally want it to throw an error. Assuming that ReactJS doesn't provide better support for this any time soon, what's the best workaround? So far, the best I've come up with is to override console.warn for tests, e.g. console.warn = function(msg) { throw new Error(msg); };