Closed 1Jesper1 closed 5 years ago
I'm not sure what you mean. PropTypes.shape
only works with an object, not with undefined or null, and Object.keys
always throws with null
or undefined
. PropTypes.shape()
is incorrect.
@ljharb React doesn't require it: See https://github.com/yannickcr/eslint-plugin-react/issues/1471
@1Jesper1 if they're passing the argument value into Object.keys()
then they do require it, since that always throws on null or undefined.
That linked issue is about the linter crashing on it, which is unrelated.
Can you provide the full stack trace, and the code for your shape
creation?
Using:
static propTypes = {
style: PropTypes.shape(),
}
crashes on return originalKeys(object);
and if you don’t include the shim, you’re saying it doesn’t crash? (note that you should also be using the es6-shim as well)
It doesn't crash when I don' include require("airbnb-js-shims");
https://github.com/airbnb/js-shims
That's very bizarre. Can you provide the entire stack trace?
TypeError: Cannot convert undefined or null to object
at keys (<anonymous>)
at Function.keys (http://localhost:9001/static/iframe.bundle.js:42468:24)
at Shape.render (http://localhost:9001/static/iframe.bundle.js:18793:39)
at finishClassComponent (http://localhost:9001/static/iframe.bundle.js:155929:31)
at updateClassComponent (http://localhost:9001/static/iframe.bundle.js:155884:24)
at beginWork (http://localhost:9001/static/iframe.bundle.js:156832:16)
at performUnitOfWork (http://localhost:9001/static/iframe.bundle.js:160500:12)
at workLoop (http://localhost:9001/static/iframe.bundle.js:160540:24)
at renderRoot (http://localhost:9001/static/iframe.bundle.js:160623:7)
at performWorkOnRoot (http://localhost:9001/static/iframe.bundle.js:161530:7)
I think the problem is in Storybook Shape.js class: Object.keys(propTypes).map(function
and if you don’t include the shim, you’re saying it doesn’t crash? (note that you should also be using the es6-shim as wel
Sorry, made the wrong assumption, still errors when not including the shim. The problem lies in Storybook. This thread can be closed.
https://github.com/es-shims/es5-shim/blob/8b0c47f4930507392d506ad956a740423dffab85/es5-shim.js#L1145
Proptype PropTypes.shape() gives error "Cannot convert undefined or null to object"