diff --git a/is/object_of.ts b/is/object_of.ts index 7121e64..e814605 100644 --- a/is/object_of.ts +++ b/is/object_of.ts @@ -43,22 +43,24 @@ export function isObjectOf< ...Object.keys(predObj), ...Object.getOwnPropertySymbols(predObj), ].map((k) => [k, predObj[k]]); - return annotate( - rewriteName( - (x: unknown): x is ObjectOf => { - if ( - x == null || - typeof x !== "object" && typeof x !== "function" || - Array.isArray(x) - ) return false; - return preds.every(([k, pred]) => pred((x as T)[k])); - }, - "isObjectOf", - predObj, - ), - "predObj", + const pred = rewriteName( + (x): x is ObjectOf => { + if (!isRecordT(x)) return false; + return preds.every(([k, pred]) => pred(x[k])); + }, + "isObjectOf", predObj, ); + return annotate(pred, "predObj", predObj); +} + +function isRecordT>>( + x: unknown, +): x is T { + if (x == null) return false; + if (typeof x !== "object" && typeof x !== "function") return false; + if (Array.isArray(x)) return false; + return true; } type ObjectOf>> = FlatType<