Skip to content

Commit 456e2b9

Browse files
lambdalisueMilly
andcommitted
refactor(is/object_of): add internal isObject function
Co-authored-by: Milly <[email protected]>
1 parent 30fe0be commit 456e2b9

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

is/object_of.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,22 @@ export function isObjectOf<
4343
...Object.keys(predObj),
4444
...Object.getOwnPropertySymbols(predObj),
4545
].map((k) => [k, predObj[k]]);
46-
return annotate(
47-
rewriteName(
48-
(x: unknown): x is ObjectOf<T> => {
49-
if (
50-
x == null ||
51-
typeof x !== "object" && typeof x !== "function" ||
52-
Array.isArray(x)
53-
) return false;
54-
return preds.every(([k, pred]) => pred((x as T)[k]));
55-
},
56-
"isObjectOf",
57-
predObj,
58-
),
59-
"predObj",
46+
const pred = rewriteName(
47+
(x): x is ObjectOf<T> => {
48+
if (!isObject(x)) return false;
49+
return preds.every(([k, pred]) => pred(x[k]));
50+
},
51+
"isObjectOf",
6052
predObj,
6153
);
54+
return annotate(pred, "predObj", predObj);
55+
}
56+
57+
function isObject(x: unknown): x is Record<PropertyKey, unknown> {
58+
if (x == null) return false;
59+
if (typeof x !== "object" && typeof x !== "function") return false;
60+
if (Array.isArray(x)) return false;
61+
return true;
6262
}
6363

6464
type ObjectOf<T extends Record<PropertyKey, Predicate<unknown>>> = FlatType<

0 commit comments

Comments
 (0)