File tree Expand file tree Collapse file tree 4 files changed +31
-12
lines changed Open diff view settings
Expand file tree Collapse file tree 4 files changed +31
-12
lines changed Open diff view settings
Original file line number Diff line number Diff line change @@ -1025,7 +1025,7 @@ export function keyof<T extends ZodObject>(schema: T): ZodLiteral<keyof T["_zod"
10251025export interface ZodObject <
10261026 /** @ts -ignore Cast variance */
10271027 out Shape extends core . $ZodShape = core . $ZodLooseShape ,
1028- out Config extends core . $ZodObjectConfig = core . $ZodObjectConfig ,
1028+ out Config extends core . $ZodObjectConfig = core . $strip ,
10291029> extends _ZodType < core . $ZodObjectInternals < Shape , Config > > ,
10301030 core . $ZodObject < Shape , Config > {
10311031 shape : Shape ;
@@ -1108,9 +1108,7 @@ export const ZodObject: core.$constructor<ZodObject> = /*@__PURE__*/ core.$const
11081108 core . $ZodObject . init ( inst , def ) ;
11091109 ZodType . init ( inst , def ) ;
11101110
1111- util . defineLazy ( inst , "shape" , ( ) => {
1112- return Object . fromEntries ( Object . entries ( inst . _zod . def . shape ) ) ;
1113- } ) ;
1111+ util . defineLazy ( inst , "shape" , ( ) => def . shape ) ;
11141112 inst . keyof = ( ) => _enum ( Object . keys ( inst . _zod . def . shape ) ) as any ;
11151113 inst . catchall = ( catchall ) => inst . clone ( { ...inst . _zod . def , catchall : catchall as any as core . $ZodType } ) as any ;
11161114 inst . passthrough = ( ) => inst . clone ( { ...inst . _zod . def , catchall : unknown ( ) } ) ;
Original file line number Diff line number Diff line change @@ -433,13 +433,35 @@ test("passthrough index signature", () => {
433433// });
434434
435435test ( "assignability" , ( ) => {
436- z . object ( { a : z . string ( ) } ) satisfies z . ZodObject ;
437- z . object ( { a : z . string ( ) } ) . catchall ( z . number ( ) ) satisfies z . ZodObject ;
436+ z . object ( { a : z . string ( ) } ) satisfies z . ZodObject < { a : z . ZodString } > ;
437+ z . object ( { a : z . string ( ) } ) . catchall ( z . number ( ) ) satisfies z . ZodObject < { a : z . ZodString } > ;
438438 z . object ( { a : z . string ( ) } ) . strict ( ) satisfies z . ZodObject ;
439439 z . object ( { } ) satisfies z . ZodObject ;
440- z . object ( { "a?" : z . string ( ) } ) satisfies z . ZodObject ;
441- z . object ( { "?a" : z . string ( ) } ) satisfies z . ZodObject ;
442440
441+ z . looseObject ( { name : z . string ( ) } ) satisfies z . ZodObject <
442+ {
443+ name : z . ZodString ;
444+ } ,
445+ z . core . $loose
446+ > ;
447+ z . looseObject ( { name : z . string ( ) } ) satisfies z . ZodObject < {
448+ name : z . ZodString ;
449+ } > ;
450+ z . strictObject ( { name : z . string ( ) } ) satisfies z . ZodObject <
451+ {
452+ name : z . ZodString ;
453+ } ,
454+ z . core . $loose
455+ > ;
456+ z . strictObject ( { name : z . string ( ) } ) satisfies z . ZodObject <
457+ {
458+ name : z . ZodString ;
459+ } ,
460+ z . core . $strict
461+ > ;
462+ z . object ( { name : z . string ( ) } ) satisfies z . ZodObject < {
463+ name : z . ZodString ;
464+ } > ;
443465 z . object ( {
444466 a : z . string ( ) ,
445467 b : z . number ( ) ,
Original file line number Diff line number Diff line change @@ -695,7 +695,7 @@ export function keyof<T extends ZodMiniObject>(schema: T): ZodMiniLiteral<keyof
695695export interface ZodMiniObject <
696696 /** @ts -ignore Cast variance */
697697 out Shape extends core . $ZodShape = core . $ZodShape ,
698- out Config extends core . $ZodObjectConfig = core . $ZodObjectConfig ,
698+ out Config extends core . $ZodObjectConfig = core . $strip ,
699699> extends ZodMiniType < any , any , core . $ZodObjectInternals < Shape , Config > > ,
700700 core . $ZodObject < Shape , Config > {
701701 shape : Shape ;
@@ -705,6 +705,7 @@ export const ZodMiniObject: core.$constructor<ZodMiniObject> = /*@__PURE__*/ cor
705705 ( inst , def ) => {
706706 core . $ZodObject . init ( inst , def ) ;
707707 ZodMiniType . init ( inst , def ) ;
708+ util . defineLazy ( inst , "shape" , ( ) => def . shape ) ;
708709 }
709710) ;
710711export function object < T extends core . $ZodLooseShape = Record < never , SomeType > > (
Original file line number Diff line number Diff line change 11import { z } from "zod/v4" ;
22
3- z ;
4-
5- console . dir ( z . literal ( Number . POSITIVE_INFINITY ) . parse ( Number . POSITIVE_INFINITY ) , { depth : null } ) ;
3+ z . string ( ) . regex ( / a s d f / ) ;
You can’t perform that action at this time.
0 commit comments