@@ -327,11 +327,7 @@ test('FormPath with type narrowing, arrays', () => {
327
327
test ( 'FormPath with type narrowing, union' , ( ) => {
328
328
type NameArrays = FormPath < Obj , string | number > ;
329
329
330
- const t1 : NameArrays = 'name' ;
331
- const t2 : NameArrays = 'points' ;
332
- const t3 : NameArrays = 'tags[3].name' ;
333
- const t4 : NameArrays = 'names[3]' ;
334
- const t5 : NameArrays = 'tags[0].parents[5]' ;
330
+ const ok : NameArrays [ ] = [ 'name' , 'points' , 'tags[3].name' , 'names[3]' , 'tags[0].parents[5]' ] ;
335
331
336
332
// @ts -expect-error incorrect path
337
333
const i1 : NameArrays = 'tags' ;
@@ -371,7 +367,6 @@ test('FormPath with any type', () => {
371
367
372
368
// @ts -expect-error Invalid path
373
369
const f1 : FP = 'nope' ;
374
- // @ts -expect-error Invalid path
375
370
const f2 : FPA = 'age[3]' ;
376
371
} ) ;
377
372
@@ -389,6 +384,23 @@ test('Schemas with built-in objects', () => {
389
384
const tf : FPL = 'name' ;
390
385
} ) ;
391
386
387
+ test ( 'Schema with nested arrays' , ( ) => {
388
+ const reportSchema = z . object ( {
389
+ reportDate : z . date ( ) ,
390
+ images : z . instanceof ( File , { message : 'Please upload a file.' } ) . array ( )
391
+ } ) ;
392
+
393
+ const schema = z . object ( {
394
+ reports : z . array ( reportSchema ) . min ( 1 , 'At least one report must be submitted' )
395
+ } ) ;
396
+
397
+ type FPL = FormPathLeaves < Infer < typeof schema > > ;
398
+
399
+ const ok : FPL [ ] = [ 'reports[3].reportDate' , 'reports[3].images[2]' ] ;
400
+ // @ts -expect-error Invalid type
401
+ const no : FPL = 'reports[3]' ;
402
+ } ) ;
403
+
392
404
///////////////////////////////////////////////////
393
405
394
406
// Recursive schema test
0 commit comments