@@ -161,41 +161,40 @@ export interface DataRouteObject extends RouteObject {
161
161
id : string ;
162
162
}
163
163
164
- type Star = "*"
164
+ type Star = "*" ;
165
165
/**
166
166
* @private
167
167
* Return string union from path string.
168
168
* @example
169
169
* PathParam<"/path/:a/:b"> // "a" | "b"
170
170
* PathParam<"/path/:a/:b/*"> // "a" | "b" | "*"
171
171
*/
172
- type PathParam <
173
- Path extends string
174
- > =
175
- // Check path string starts with slash and a param string.
176
- Path extends `:${infer Param } /${infer Rest } `
177
- ? Param | PathParam < Rest >
178
- // Check path string is a param string.
179
- : Path extends `:${infer Param } `
180
- ? Param
181
- // Check path string ends with slash and a param string.
182
- : Path extends `${any } /:${infer Param } `
183
- ? PathParam < `:${Param } `>
184
- // Check path string ends with slash and a star.
185
- : Path extends `${any } /${Star } `
186
- ? Star
187
- // Check string is star.
188
- : Path extends Star
189
- ? Star
190
- : never
172
+ type PathParam < Path extends string > =
173
+ // Check path string starts with slash and a param string.
174
+ Path extends `:${infer Param } /${infer Rest } `
175
+ ? Param | PathParam < Rest >
176
+ : // Check path string is a param string.
177
+ Path extends `:${infer Param } `
178
+ ? Param
179
+ : // Check path string ends with slash and a param string.
180
+ Path extends `${any } /:${infer Param } `
181
+ ? PathParam < `:${Param } `>
182
+ : // Check path string ends with slash and a star.
183
+ Path extends `${any } /${Star } `
184
+ ? Star
185
+ : // Check string is star.
186
+ Path extends Star
187
+ ? Star
188
+ : never ;
191
189
192
190
// Attempt to parse the given string segment. If it fails, then just return the
193
191
// plain string type as a default fallback. Otherwise return the union of the
194
192
// parsed string literals that were referenced as dynamic segments in the route.
195
- export type ParamParseKey < Segment extends string > =
196
- [ PathParam < Segment > ] extends [ never ]
197
- ? PathParam < Segment >
198
- : string ;
193
+ export type ParamParseKey < Segment extends string > = [
194
+ PathParam < Segment >
195
+ ] extends [ never ]
196
+ ? PathParam < Segment >
197
+ : string ;
199
198
200
199
/**
201
200
* The parameters that were parsed from the URL path.
@@ -464,21 +463,22 @@ function matchRouteBranch<
464
463
*
465
464
* @see https://reactrouter.com/docs/en/v6/utils/generate-path
466
465
*/
467
- export function generatePath < Path extends string > ( path : Path , params : {
468
- [ key in PathParam < Path > ] : string
469
- } = { } as any ) : string {
466
+ export function generatePath < Path extends string > (
467
+ path : Path ,
468
+ params : {
469
+ [ key in PathParam < Path > ] : string ;
470
+ } = { } as any
471
+ ) : string {
470
472
return path
471
473
. replace ( / : ( \w + ) / g, ( _ , key : PathParam < Path > ) => {
472
474
invariant ( params [ key ] != null , `Missing ":${ key } " param` ) ;
473
475
return params [ key ] ! ;
474
476
} )
475
- . replace ( / \/ * \* $ / , ( _ ) =>
476
- {
477
- const star = "*" as PathParam < Path >
478
-
479
- return params [ star ] == null ? "" : params [ star ] . replace ( / ^ \/ * / , "/" )
480
- }
481
- ) ;
477
+ . replace ( / \/ * \* $ / , ( _ ) => {
478
+ const star = "*" as PathParam < Path > ;
479
+
480
+ return params [ star ] == null ? "" : params [ star ] . replace ( / ^ \/ * / , "/" ) ;
481
+ } ) ;
482
482
}
483
483
484
484
/**
0 commit comments