Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ export function isOptionalOf<T>(
}
return Object.defineProperties(
setPredicateFactoryMetadata(
(x: unknown): x is Predicate<T | undefined> => x === undefined || pred(x),
(x: unknown): x is T | undefined => x === undefined || pred(x),
{ name: "isOptionalOf", args: [pred] },
),
{ optional: { value: true as const } },
Expand Down Expand Up @@ -1145,7 +1145,11 @@ export function isObjectOf<
}
return setPredicateFactoryMetadata(
(x: unknown): x is ObjectOf<T> => {
if (x == null || typeof x !== "object" || Array.isArray(x)) return false;
if (
x == null ||
typeof x !== "object" && typeof x !== "function" ||
Array.isArray(x)
) return false;
// Check each values
for (const k in predObj) {
if (!predObj[k]((x as T)[k])) return false;
Expand Down
7 changes: 7 additions & 0 deletions is_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,13 @@ Deno.test("isObjectOf<T>", async (t) => {
true,
"Object have an unknown property",
);
assertEquals(
isObjectOf(predObj)(
Object.assign(() => void 0, { a: 0, b: "a", c: true }),
),
true,
"Function object",
);
});
await t.step("returns false on non T object", () => {
const predObj = {
Expand Down