Skip to content

Commit dc20dfa

Browse files
fix: isObj to look for prototype object of prototype
1 parent e258669 commit dc20dfa

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

packages/std/__tests__/types/isObj.spec.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ describe('Types > isObj', () => {
3737
this.name = name;
3838
}
3939
}
40-
4140
expect(isObj(new Person('x'))).toBe(false);
4241
expect(isObj(new (fun as any)(1))).toBe(false);
4342
});
@@ -47,5 +46,14 @@ describe('Types > isObj', () => {
4746
expect(isObj({ a: 1 })).toBe(true);
4847
expect(isObj(new Object())).toBe(true);
4948
expect(isObj(Object.create(null))).toBe(true);
49+
50+
if (globalThis.structuredClone) {
51+
const obj = {
52+
a: 1,
53+
b: 'Hello world',
54+
};
55+
const clone = structuredClone(obj);
56+
expect(isObj(structuredClone(obj))).toBe(true);
57+
}
5058
});
5159
});

packages/std/src/types/isObj.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ export default function isObj(val: unknown): val is object {
1818

1919
const p = Object.getPrototypeOf(val);
2020

21-
return p === null || p === Object.prototype;
21+
return p === null || Object.getPrototypeOf(p) === null;
2222
}

0 commit comments

Comments
 (0)