22import type {
33 StringPath ,
44 FormPathType ,
5+ FormPathArrays ,
56 StringPathLeaves
67} from '$lib/stringPath' ;
78import { test } from 'vitest' ;
9+ import type { z } from 'zod' ;
810
911type Obj = {
1012 name : string ;
@@ -16,29 +18,53 @@ type Obj = {
1618 tags :
1719 | ( { id : number ; name : string ; parents : number [ ] } | null ) [ ]
1820 | undefined ;
21+ names : string [ ] ;
1922} ;
2023
2124const i = 7 + 3 ;
2225
2326type Test = StringPath < Obj > ;
27+ type Arrays = FormPathArrays < Obj > ;
2428
2529test ( 'StringPath' , ( ) => {
26- const a1 : Test = 'name' ;
27- const a2 : Test = 'city' ;
28- const a3 : Test = 'tags' ;
29- const a4 : Test = 'city.name' ;
30- const a5 : Test = 'tags[3]' ;
31- const a6 : Test = 'tags[3].name' ;
32- const a7 : Test = 'scores[3][4]' ;
30+ const t1 : Test = 'name' ;
31+ const t2 : Test = 'city' ;
32+ const t3 : Test = 'tags' ;
33+ const t4 : Test = 'city.name' ;
34+ const t5 : Test = 'tags[3]' ;
35+ const t6 : Test = 'tags[3].name' ;
36+ const t7 : Test = 'scores[3][4]' ;
37+ const t8 : Test = 'names[3]' ;
3338
3439 // @ts -expect-error incorrect path
35- const n8 : Test = 'city[3]' ;
40+ const t1e : Test = 'city[3]' ;
3641 // @ts -expect-error incorrect path
37- const n7 : Test = 'city.nope' ;
42+ const t2e : Test = 'city.nope' ;
3843 // @ts -expect-error incorrect path
39- const n9 : Test = 'tags[4].nope' ;
44+ const t3e : Test = 'tags[4].nope' ;
4045 // @ts -expect-error incorrect path
41- const n0 : Test = 'nope' ;
46+ const t4e : Test = 'nope' ;
47+ // @ts -expect-error incorrect path
48+ const t5e : Test = 'names[2].test' ;
49+
50+ const a1 : Arrays = 'scores' ;
51+ const a2 : Arrays = 'scores[3]' ;
52+ const a3 : Arrays = 'tags' ;
53+ const a4 : Arrays = 'tags[2].parents' ;
54+ const a5 : Arrays = 'names' ;
55+
56+ // @ts -expect-error incorrect path
57+ const a1e : Arrays = 'name' ;
58+ // @ts -expect-error incorrect path
59+ const a2e : Arrays = 'points' ;
60+ // @ts -expect-error incorrect path
61+ const a3e : Arrays = 'scores[2][1]' ;
62+ // @ts -expect-error incorrect path
63+ const a4e : Arrays = 'city' ;
64+ // @ts -expect-error incorrect path
65+ const a5e : Arrays = 'tags[1]' ;
66+ // @ts -expect-error incorrect path
67+ const a6e : Arrays = 'names[1]' ;
4268} ) ;
4369
4470function checkPath < T = never > ( ) {
0 commit comments