Objects with null prototype cause fast-deep-equal to throw an error
See original GitHub issueExample code:
fastDeepEqual(Object.create(null, {a:true}), {a:true})
This will throw an error, the line below calls .valueOf()
which is not a method for objects with a null prototype.
https://github.com/epoberezkin/fast-deep-equal/blob/master/src/index.jst#L51
Issue Analytics
- State:
- Created 4 years ago
- Reactions:18
- Comments:5 (2 by maintainers)
Top Results From Across the Web
how to fix [Object: null prototype] { title: 'product' }
I'm wondering if this actually is an error with express or just a propriety that its been added to express recently , because...
Read more >JavaScript and object with null prototype - LinkedIn
Object with null prototype and its purpose If you create an object in JavaScript - it has some methods by default, such as...
Read more >core-helpers - Remirror
Throw an error if the referenced property is undefined . Signature: ... A deep merge which only merges plain objects and Arrays. It...
Read more >johnrom/formik - UNPKG
isArray;\nvar keyList = Object.keys;\nvar hasProp = Object.prototype. ... some other error. we should definitely know about these\n throw error;\n }\n};\n" ...
Read more >jest typeerror: class extends value - You.com | The AI Search ...
I get the following error: FAIL e2e/firstTest.e2e.jsrun... ○ Test suite failed to run TypeError: Class extends value #<Object> is not a constructor or...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you - I commented there.
The design decision here is to consider instances of different classes (i.e. with different prototypes in JS) as not equal, even if they have the same properties. So if
null
prototype support is added (which I am considering), objects in your example would not throw an exception, but would return false - I believe it is different from what you expect.I am also considering to introduce a version of this function that ignores classes/prototypes and only checks properties, with some specific exceptions (e.g. Date and RegExp).
To address it now, any possible workaround should be used in the application code.
I don’t use null prototype directly, but
graphql-js
uses them for return values and I want to make assertions on those return values.Some quick issue searching shows some reasoning for using null prototype.
https://github.com/graphql/graphql-js/pull/504#issuecomment-250343574