Skip to content

Commit 14a83f7

Browse files
committed
🐛 Do NOT check required keys in isObjectOf
Some instance attributes are non enumerable, so we should not check.
1 parent b01d673 commit 14a83f7

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

is/factory.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { FlatType } from "../_typeutil.ts";
22
import type { Predicate, PredicateType } from "./type.ts";
3-
import { isOptional, isOptionalOf, isReadonlyOf } from "./annotation.ts";
3+
import { isOptionalOf, isReadonlyOf } from "./annotation.ts";
44
import {
55
isAny,
66
isArray,
@@ -506,18 +506,12 @@ export function isObjectOf<
506506
// deno-lint-ignore no-explicit-any
507507
return isStrictOf(isObjectOf(predObj)) as any;
508508
}
509-
const requiredKeys = Object.entries(predObj)
510-
.filter(([_, v]) => !isWithOptional(v))
511-
.map(([k]) => k);
512509
return setPredicateFactoryMetadata(
513510
(x: unknown): x is ObjectOf<T> => {
514511
if (x == null || typeof x !== "object") return false;
515-
// Check required keys
516-
const s = new Set(Object.keys(x));
517-
if (requiredKeys.some((k) => !s.has(k))) return false;
518512
// Check each values
519513
for (const k in predObj) {
520-
if (!predObj[k](x[k])) return false;
514+
if (!predObj[k]((x as T)[k])) return false;
521515
}
522516
return true;
523517
},
@@ -529,13 +523,6 @@ type WithOptional =
529523
| WithMetadata<GetMetadata<ReturnType<typeof isOptionalOf>>>
530524
| { optional: true }; // For backward compatibility
531525

532-
function isWithOptional<T extends Predicate<unknown>>(
533-
pred: T,
534-
): pred is T & WithOptional {
535-
// deno-lint-ignore no-explicit-any
536-
return isOptional(pred) || (pred as any).optional === true;
537-
}
538-
539526
type ObjectOf<T extends Record<PropertyKey, Predicate<unknown>>> = FlatType<
540527
// Non optional
541528
& {

0 commit comments

Comments
 (0)