11// Test this file by running:
2- // npx tsc --noEmit test/node/pattern-match.test .ts
2+ // npx tsc --noEmit test/node/pattern-match.types .ts
33
4- type RoutePropsNarrow < Re extends string > = Re extends '*'
5- ? { params : { } ; rest : string }
6-
7- : Re extends `:${infer placeholder } ?/${infer rest } `
8- ? { [ k in placeholder ] ?: string } & { params : RoutePropsNarrow < rest > [ 'params' ] & { [ k in placeholder ] ?: string } } & Omit < RoutePropsNarrow < rest > , 'params' >
9-
10- : Re extends `:${infer placeholder } /${infer rest } `
11- ? { [ k in placeholder ] : string } & { params : RoutePropsNarrow < rest > [ 'params' ] & { [ k in placeholder ] : string } } & Omit < RoutePropsNarrow < rest > , 'params' >
12-
13- : Re extends `:${infer placeholder } ?`
14- ? { [ k in placeholder ] ?: string } & { params : { [ k in placeholder ] ?: string } }
15-
16- : Re extends `:${infer placeholder } *`
17- ? { [ k in placeholder ] ?: string } & { params : { [ k in placeholder ] ?: string } }
18-
19- : Re extends `:${infer placeholder } +`
20- ? { [ k in placeholder ] : string } & { params : { [ k in placeholder ] : string } }
21-
22- : Re extends `:${infer placeholder } `
23- ? { [ k in placeholder ] : string } & { params : { [ k in placeholder ] : string } }
24-
25- : Re extends ( `/${infer rest } ` | `${infer _ } /${infer rest } `)
26- ? RoutePropsNarrow < rest >
27-
28- : { params : { } } ;
4+ import type { RoutePropsForPath } from '../../src/router.js' ;
295
306// Test utils
317
@@ -36,92 +12,92 @@ type isWeakEqualsType<T, U> = T extends U ? true : false;
3612
3713// Base route test
3814const test1 : isEqualsType <
39- RoutePropsNarrow < '/' > ,
15+ RoutePropsForPath < '/' > ,
4016 { params : { } }
4117> = true ;
4218
4319const test1_1 : isEqualsType <
44- RoutePropsNarrow < '/' > ,
20+ RoutePropsForPath < '/' > ,
4521 { arbitrary : { } }
4622> = false ;
4723
4824// Param route test
4925const test2 : isEqualsType <
50- RoutePropsNarrow < '/user/:id' > ,
26+ RoutePropsForPath < '/user/:id' > ,
5127 { params : { id : string } , id : string }
5228> = true ;
5329
5430const test2_weak : isWeakEqualsType <
55- RoutePropsNarrow < '/user/:id' > ,
31+ RoutePropsForPath < '/user/:id' > ,
5632 { params : { id : string } }
5733> = true ;
5834
5935// Param rest segment test
6036const test3 : isEqualsType <
61- RoutePropsNarrow < '/user/*' > ,
37+ RoutePropsForPath < '/user/*' > ,
6238 { params : { } , rest : string }
6339> = true ;
6440
6541const test3_1 : isEqualsType <
66- RoutePropsNarrow < '/*' > ,
42+ RoutePropsForPath < '/*' > ,
6743 { params : { } , rest : string }
6844> = true ;
6945
7046const test3_2 : isEqualsType <
71- RoutePropsNarrow < '*' > ,
47+ RoutePropsForPath < '*' > ,
7248 { params : { } , rest : string }
7349> = true ;
7450
7551// Param route with rest segment test
7652const test4 : isEqualsType <
77- RoutePropsNarrow < '/user/:id/*' > ,
53+ RoutePropsForPath < '/user/:id/*' > ,
7854 { params : { id : string } , id : string , rest : string }
7955> = true ;
8056
8157// Optional param route test
8258const test5 : isEqualsType <
83- RoutePropsNarrow < '/user/:id?' > ,
59+ RoutePropsForPath < '/user/:id?' > ,
8460 { params : { id ?: string } , id ?: string }
8561> = true ;
8662
8763// Optional rest param route "/:x*" test
8864const test6 : isEqualsType <
89- RoutePropsNarrow < '/user/:id*' > ,
65+ RoutePropsForPath < '/user/:id*' > ,
9066 { params : { id ?: string } , id ?: string }
9167> = true ;
9268
9369// rest param should not be present
9470const test6_error : isEqualsType <
95- RoutePropsNarrow < '/user/:id*' > ,
71+ RoutePropsForPath < '/user/:id*' > ,
9672 { params : { id : string } , rest : string }
9773> = false ;
9874
9975// Rest param route "/:x+" test
10076const test7 : isEqualsType <
101- RoutePropsNarrow < '/user/:id+' > ,
77+ RoutePropsForPath < '/user/:id+' > ,
10278 { params : { id : string } , id : string }
10379> = true ;
10480
10581// rest param should not be present
10682const test7_error : isEqualsType <
107- RoutePropsNarrow < '/user/:id+' > ,
83+ RoutePropsForPath < '/user/:id+' > ,
10884 { params : { id : string } , id : string , rest : string }
10985> = false ;
11086
11187// Handles leading/trailing slashes test
11288const test8 : isEqualsType <
113- RoutePropsNarrow < '/about-late/:seg1/:seg2/' > ,
89+ RoutePropsForPath < '/about-late/:seg1/:seg2/' > ,
11490 { params : { seg1 : string ; seg2 : string } , seg1 : string , seg2 : string }
11591> = true ;
11692
11793// Multiple params test (from overwrite properties test)
11894const test9 : isEqualsType <
119- RoutePropsNarrow < '/:path/:query' > ,
95+ RoutePropsForPath < '/:path/:query' > ,
12096 { params : { path : string ; query : string } , path : string , query : string }
12197> = true ;
12298
12399// Empty route test
124100const test10 : isEqualsType <
125- RoutePropsNarrow < '' > ,
101+ RoutePropsForPath < '' > ,
126102 { params : { } }
127103> = true ;
0 commit comments