File tree Expand file tree Collapse file tree 1 file changed +0
-25
lines changed Expand file tree Collapse file tree 1 file changed +0
-25
lines changed Original file line number Diff line number Diff line change @@ -8,31 +8,6 @@ title: generatePath
8
8
<summary >Type declaration</summary >
9
9
10
10
``` tsx
11
- // Recursive helper for finding path parameters in the absence of wildcards
12
- type _PathParam <Path extends string > =
13
- // split path into individual path segments
14
- Path extends ` ${infer L }/${infer R } ` ? _PathParam <L > | _PathParam <R > :
15
- // find params after `:`
16
- Path extends ` ${string }:${infer Param } ` ? Param :
17
- // otherwise, there aren't any params present
18
- never
19
-
20
- /**
21
- * Examples:
22
- * "/a/b/*" -> "/*"
23
- * ":a" -> "a"
24
- * "/a/:b" -> "b"
25
- * "/:a/:b" -> "a" | "b"
26
- */
27
- type PathParam <Path extends string > =
28
- // check if path is just a wildcard
29
- Path extends " *" ? " *" :
30
- // look for wildcard at the end of the path
31
- Path extends ` ${infer Rest }/* ` ? " *" | _PathParam <Rest > :
32
- // look for params in the absence of wildcards
33
- _PathParam <Path >
34
-
35
-
36
11
declare function generatePath<Path extends string >(
37
12
path : Path ,
38
13
params ? : {
You can’t perform that action at this time.
0 commit comments