Skip to content

Commit

Permalink
fix: isObj to look for prototype object of prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
Thanga-Ganapathy committed Apr 29, 2024
1 parent e258669 commit dc20dfa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion packages/std/__tests__/types/isObj.spec.ts
Expand Up @@ -37,7 +37,6 @@ describe('Types > isObj', () => {
this.name = name;
}
}

expect(isObj(new Person('x'))).toBe(false);
expect(isObj(new (fun as any)(1))).toBe(false);
});
Expand All @@ -47,5 +46,14 @@ describe('Types > isObj', () => {
expect(isObj({ a: 1 })).toBe(true);
expect(isObj(new Object())).toBe(true);
expect(isObj(Object.create(null))).toBe(true);

if (globalThis.structuredClone) {
const obj = {
a: 1,
b: 'Hello world',
};
const clone = structuredClone(obj);
expect(isObj(structuredClone(obj))).toBe(true);
}
});
});
2 changes: 1 addition & 1 deletion packages/std/src/types/isObj.ts
Expand Up @@ -18,5 +18,5 @@ export default function isObj(val: unknown): val is object {

const p = Object.getPrototypeOf(val);

return p === null || p === Object.prototype;
return p === null || Object.getPrototypeOf(p) === null;
}

0 comments on commit dc20dfa

Please sign in to comment.