Skip to content

Commit 38607b0

Browse files
authored
Merge pull request #75 from Milly/function-object
`isObjectOf` allows function object
2 parents b89d255 + 51091e2 commit 38607b0

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

is.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ export function isOptionalOf<T>(
454454
}
455455
return Object.defineProperties(
456456
setPredicateFactoryMetadata(
457-
(x: unknown): x is Predicate<T | undefined> => x === undefined || pred(x),
457+
(x: unknown): x is T | undefined => x === undefined || pred(x),
458458
{ name: "isOptionalOf", args: [pred] },
459459
),
460460
{ optional: { value: true as const } },
@@ -1157,7 +1157,11 @@ export function isObjectOf<
11571157
}
11581158
return setPredicateFactoryMetadata(
11591159
(x: unknown): x is ObjectOf<T> => {
1160-
if (x == null || typeof x !== "object" || Array.isArray(x)) return false;
1160+
if (
1161+
x == null ||
1162+
typeof x !== "object" && typeof x !== "function" ||
1163+
Array.isArray(x)
1164+
) return false;
11611165
// Check each values
11621166
for (const k in predObj) {
11631167
if (!predObj[k]((x as T)[k])) return false;

is_test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,13 @@ Deno.test("isObjectOf<T>", async (t) => {
11371137
true,
11381138
"Object have an unknown property",
11391139
);
1140+
assertEquals(
1141+
isObjectOf(predObj)(
1142+
Object.assign(() => void 0, { a: 0, b: "a", c: true }),
1143+
),
1144+
true,
1145+
"Function object",
1146+
);
11401147
});
11411148
await t.step("returns false on non T object", () => {
11421149
const predObj = {

0 commit comments

Comments
 (0)