@@ -487,6 +487,38 @@ test("partialRecord with z.literal([key, ...])", () => {
487487 ` ) ;
488488} ) ;
489489
490+ test ( "partialRecord with numeric literal keys" , ( ) => {
491+ const Keys = z . literal ( [ 1 , 2 , 3 ] ) ;
492+ const schema = z . partialRecord ( Keys , z . string ( ) ) ;
493+ type Schema = z . infer < typeof schema > ;
494+ expectTypeOf < Schema > ( ) . toEqualTypeOf < Partial < Record < 1 | 2 | 3 , string > > > ( ) ;
495+
496+ // Should parse valid partials with numeric keys (as strings in JS objects)
497+ expect ( schema . parse ( { } ) ) . toEqual ( { } ) ;
498+ expect ( schema . parse ( { 1 : "one" } ) ) . toEqual ( { 1 : "one" } ) ;
499+ expect ( schema . parse ( { 2 : "two" , 3 : "three" } ) ) . toEqual ( { 2 : "two" , 3 : "three" } ) ;
500+
501+ // Should fail with unrecognized key
502+ expect ( schema . safeParse ( { 4 : "four" } ) . success ) . toBe ( false ) ;
503+ } ) ;
504+
505+ test ( "partialRecord with union of string and numeric literal keys" , ( ) => {
506+ const StringKeys = z . literal ( [ "a" , "b" , "c" ] ) ;
507+ const NumericKeys = z . literal ( [ 1 , 2 , 3 ] ) ;
508+ const schema = z . partialRecord ( z . union ( [ StringKeys , NumericKeys ] ) , z . string ( ) ) ;
509+ type Schema = z . infer < typeof schema > ;
510+ expectTypeOf < Schema > ( ) . toEqualTypeOf < Partial < Record < "a" | "b" | "c" | 1 | 2 | 3 , string > > > ( ) ;
511+
512+ // Should parse valid partials with mixed keys
513+ expect ( schema . parse ( { } ) ) . toEqual ( { } ) ;
514+ expect ( schema . parse ( { a : "1" , 2 : "4" } ) ) . toEqual ( { a : "1" , 2 : "4" } ) ;
515+ expect ( schema . parse ( { a : "a" , b : "b" , 1 : "1" , 2 : "2" } ) ) . toEqual ( { a : "a" , b : "b" , 1 : "1" , 2 : "2" } ) ;
516+
517+ // Should fail with unrecognized key
518+ expect ( schema . safeParse ( { d : "d" } ) . success ) . toBe ( false ) ;
519+ expect ( schema . safeParse ( { 4 : "4" } ) . success ) . toBe ( false ) ;
520+ } ) ;
521+
490522test ( "looseRecord passes through non-matching keys" , ( ) => {
491523 const schema = z . looseRecord ( z . string ( ) . regex ( / ^ S _ / ) , z . string ( ) ) ;
492524
0 commit comments