11import type { FlatType } from "../_typeutil.ts" ;
22import type { Predicate , PredicateType } from "./type.ts" ;
3- import { isOptional , isOptionalOf , isReadonlyOf } from "./annotation.ts" ;
3+ import { isOptionalOf , isReadonlyOf } from "./annotation.ts" ;
44import {
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 > => {
514- if ( ! isRecord ( x ) ) return false ;
515- // Check required keys
516- const s = new Set ( Object . keys ( x ) ) ;
517- if ( requiredKeys . some ( ( k ) => ! s . has ( k ) ) ) return false ;
511+ if ( x == null || typeof x !== "object" ) 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-
539526type ObjectOf < T extends Record < PropertyKey , Predicate < unknown > > > = FlatType <
540527 // Non optional
541528 & {
0 commit comments