Closed aswind7 closed 5 months ago
export function isPlainObject(payload: any): payload is PlainObject {
if (getType(payload) !== 'Object') return false
const prototype = Object.getPrototypeOf(payload)
// Fix
if (prototype === null) return true;
return !!prototype && prototype.constructor === Object && prototype === Object.prototype
}
I find in test this. Why?
expect(isPlainObject(Object.create(null))).toEqual(false)
isPlainObject
is opinionated. I want it to only match objects created with regular object constructor. Eg. const obj = {}
If you don't like my interpretation of isPlainObject
you can use isAnyObject
, which will better fit your use-case.
it can be this: