From 748257ee4916a2fd1c6845acc19fab651a1c9562 Mon Sep 17 00:00:00 2001 From: Milly Date: Sun, 14 Apr 2024 16:45:36 +0900 Subject: [PATCH 1/2] :bug: Remove unnecessary generics --- is.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/is.ts b/is.ts index 7b30729..48139fc 100644 --- a/is.ts +++ b/is.ts @@ -454,7 +454,7 @@ export function isOptionalOf( } return Object.defineProperties( setPredicateFactoryMetadata( - (x: unknown): x is Predicate => x === undefined || pred(x), + (x: unknown): x is T | undefined => x === undefined || pred(x), { name: "isOptionalOf", args: [pred] }, ), { optional: { value: true as const } }, From 51091e2ab22ef50521a568faa30a58a84e1a2487 Mon Sep 17 00:00:00 2001 From: Milly Date: Sun, 14 Apr 2024 16:46:52 +0900 Subject: [PATCH 2/2] :+1: `isObjectOf` allows function object --- is.ts | 6 +++++- is_test.ts | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/is.ts b/is.ts index 48139fc..47b8c9e 100644 --- a/is.ts +++ b/is.ts @@ -1145,7 +1145,11 @@ export function isObjectOf< } return setPredicateFactoryMetadata( (x: unknown): x is ObjectOf => { - 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; diff --git a/is_test.ts b/is_test.ts index d2858dc..1f649cc 100644 --- a/is_test.ts +++ b/is_test.ts @@ -1137,6 +1137,13 @@ Deno.test("isObjectOf", 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 = {