@@ -27,34 +27,32 @@ import { Expression } from "../params";
2727 *
2828 * For example Split<"a/b/c", "/"> is ['a' | "b" | "c"]
2929 */
30- export type Split < S extends string , D extends string > =
31- // A non-literal string splits into a string[]
32- string extends S
33- ? string [ ]
34- : // A literal empty string turns into a zero-tuple
30+ export type Split < S extends string , D extends string > = string extends S // A non-literal string splits into a string[]
31+ ? string [ ]
32+ : // A literal empty string turns into a zero-tuple
3533 S extends ""
3634 ? [ ]
3735 : // Split the string; Head may be the empty string
38- S extends `${D } ${infer Tail } `
39- ? [ ...Split < Tail , D > ]
40- : S extends `${infer Head } ${D } ${infer Tail } `
41- ? // Drop types that are exactly string; they'll eat up literal string types
42- string extends Head
36+ S extends `${D } ${infer Tail } `
4337 ? [ ...Split < Tail , D > ]
44- : [ Head , ...Split < Tail , D > ]
45- : // A string without delimiters splits into an array of itself
46- [ S ] ;
38+ : S extends `${infer Head } ${D } ${infer Tail } `
39+ ? // Drop types that are exactly string; they'll eat up literal string types
40+ string extends Head
41+ ? [ ...Split < Tail , D > ]
42+ : [ Head , ...Split < Tail , D > ]
43+ : // A string without delimiters splits into an array of itself
44+ [ S ] ;
4745
4846/**
4947 * A type that ensure that type S is not null or undefined.
5048 */
5149export type NullSafe < S extends null | undefined | string > = S extends null
5250 ? never
5351 : S extends undefined
54- ? never
55- : S extends string
56- ? S
57- : never ;
52+ ? never
53+ : S extends string
54+ ? S
55+ : never ;
5856
5957/**
6058 * A type that extracts parameter name enclosed in bracket as string.
@@ -67,10 +65,10 @@ export type NullSafe<S extends null | undefined | string> = S extends null
6765export type Extract < Part extends string > = Part extends `{${infer Param } =**}`
6866 ? Param
6967 : Part extends `{${infer Param } =*}`
70- ? Param
71- : Part extends `{${infer Param } }`
72- ? Param
73- : never ;
68+ ? Param
69+ : Part extends `{${infer Param } }`
70+ ? Param
71+ : never ;
7472
7573/**
7674 * A type that maps all parameter capture gropus into keys of a record.
@@ -85,12 +83,12 @@ export type ParamsOf<PathPattern extends string | Expression<string>> =
8583 PathPattern extends Expression < string >
8684 ? Record < string , string >
8785 : string extends PathPattern
88- ? Record < string , string >
89- : {
90- // N.B. I'm not sure why PathPattern isn't detected to not be an
91- // Expression<string> per the check above. Since we have the check above
92- // The Exclude call should be safe.
93- [ Key in Extract <
94- Split < NullSafe < Exclude < PathPattern , Expression < string > > > , "/" > [ number ]
95- > ] : string ;
96- } ;
86+ ? Record < string , string >
87+ : {
88+ // N.B. I'm not sure why PathPattern isn't detected to not be an
89+ // Expression<string> per the check above. Since we have the check above
90+ // The Exclude call should be safe.
91+ [ Key in Extract <
92+ Split < NullSafe < Exclude < PathPattern , Expression < string > > > , "/" > [ number ]
93+ > ] : string ;
94+ } ;
0 commit comments