facebook / prop-types

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

No warnings for providing an undefined function. #286

Closed jasperdunn closed 5 years ago

jasperdunn commented 5 years ago

This happened to me a few weeks ago. Very silly mistake, I'm sure its happened to other people too.

I had imported a function that didn't exist, and it took me a good half an hour to find out why my app was broken, no errors, the page just wouldn't render anything.

here is the silly code that caused the issue:

import { string, shapeOf } from 'prop-types'

MyComponent.propTypes = {
    myProp: shapeOf({variable1: string})
}

export default MyComponent() {
    return // my component code
}

of course there is no shapeOf function exported from prop-types 😜

it would be nice if the propTypes interpreter checked if the value actually existed

ljharb commented 5 years ago

eslint-plugin-import can check the import for you; simply evaluating the module in tests would immediately tell you what happened.

propTypes aren't the only thing you should be using for quality :-)

jasperdunn commented 5 years ago

You're a legend @ljharb thanks