Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot convert undefined or null to object PropTypes.shape() #461

Closed
1Jesper1 opened this issue Apr 23, 2019 · 9 comments
Closed

Cannot convert undefined or null to object PropTypes.shape() #461

1Jesper1 opened this issue Apr 23, 2019 · 9 comments

Comments

@1Jesper1
Copy link

return originalKeys(object);

Proptype PropTypes.shape() gives error "Cannot convert undefined or null to object"

@ljharb
Copy link
Member

ljharb commented Apr 24, 2019

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 ljharb closed this as completed Apr 24, 2019
@1Jesper1
Copy link
Author

1Jesper1 commented Apr 24, 2019

@ljharb React doesn't require it: See jsx-eslint/eslint-plugin-react#1471

@ljharb
Copy link
Member

ljharb commented Apr 24, 2019

@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?

@1Jesper1
Copy link
Author

1Jesper1 commented Apr 25, 2019

Using:

static propTypes = {
		style: PropTypes.shape(),
	}

crashes on return originalKeys(object);

@ljharb
Copy link
Member

ljharb commented Apr 25, 2019

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)

@1Jesper1
Copy link
Author

It doesn't crash when I don' include require("airbnb-js-shims"); https://github.com/airbnb/js-shims

@ljharb
Copy link
Member

ljharb commented Apr 26, 2019

That's very bizarre. Can you provide the entire stack trace?

@1Jesper1
Copy link
Author

 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

@1Jesper1
Copy link
Author

1Jesper1 commented Apr 26, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants