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

Change isPlainObject to support objects created in a different context #3068



Copy link

keeganstreet commented Mar 19, 2020

To resolve #3066

export default (x: any): boolean =>
x !== null &&
typeof x === 'object' &&
x.toString() === '[object Object]' &&

This comment has been minimized.

Copy link

kitten Mar 19, 2020


Like indicated in the PR, this will need to be Object.prototype.toString to support objects with toStrung, including Object.create(null) 🙌

This comment has been minimized.

Copy link

keeganstreet Mar 19, 2020

Author Contributor

Ah yes of course, we can't call toString()if it doesn't exist on that object.

The problem I was trying to address by using x.toString() instead of was to call a custom toString when it exists:

class MyClass {
  toString() {
    return "[object MyClass]"
const m = new MyClass();; // "[object Object]" <-- does not call the custom toString method
m.toString(); // "[object MyClass]"

I can solve this by using: (x.toString ? x.toString() : === '[object Object]'


This comment has been minimized.

Copy link
Contributor Author

keeganstreet commented Mar 23, 2020

Hi @kitten, are you happy with this now that it has been updated?


This comment has been minimized.

Copy link

shadforth commented Mar 27, 2020

Looking forward to seeing this in action! 👏

Copy link

probablyup left a comment


@probablyup probablyup merged commit 843b018 into styled-components:master Apr 7, 2020
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked issues

Successfully merging this pull request may close these issues.

4 participants
You can’t perform that action at this time.