@@ -10,19 +10,19 @@ function parseQueryValues(value: string[] | string): string[] {
10
10
return Array . isArray ( value ) ? value : [ value ] ;
11
11
}
12
12
13
- export function parseStringParam (
13
+ export function parseStringParam < T extends string | undefined > (
14
14
paramValue : string [ ] | string | undefined ,
15
- defaultValue : string | undefined = undefined ,
16
- ) : string | undefined {
15
+ defaultValue : T = undefined as T ,
16
+ ) : string | T {
17
17
const parsedValue = parseQueryValue ( paramValue ) ;
18
18
19
19
return parsedValue || defaultValue ;
20
20
}
21
21
22
- export function parseNumberParam (
22
+ export function parseNumberParam < T extends number | undefined > (
23
23
paramValue : string [ ] | string | undefined ,
24
- defaultValue : number | undefined = NaN ,
25
- ) : number {
24
+ defaultValue : T = undefined as T ,
25
+ ) : number | T {
26
26
const parsedValue = parseQueryValue ( paramValue ) ;
27
27
28
28
return Number ( parsedValue ) || defaultValue ;
@@ -37,21 +37,21 @@ export function parseJoinedStringParam(
37
37
return parsedValue ?. split ( separator ) || [ ] ;
38
38
}
39
39
40
- export function parseStringParams (
40
+ export function parseStringParams < T extends string [ ] | undefined > (
41
41
paramValue : string [ ] | string | undefined ,
42
- defaultValue : string [ ] | undefined = undefined ,
43
- ) : string [ ] | undefined {
42
+ defaultValue : T = undefined as T ,
43
+ ) : string [ ] | T {
44
44
if ( ! paramValue || paramValue . length === 0 ) {
45
45
return defaultValue ;
46
46
}
47
47
48
48
return parseQueryValues ( paramValue ) ;
49
49
}
50
50
51
- export function parseNumberParams (
51
+ export function parseNumberParams < T extends number [ ] | undefined > (
52
52
paramValue : string [ ] | string | undefined ,
53
- defaultValue : number [ ] | undefined = undefined ,
54
- ) : number [ ] | undefined {
53
+ defaultValue : T = undefined as T ,
54
+ ) : number [ ] | T {
55
55
if ( ! paramValue ) {
56
56
return defaultValue ;
57
57
}
0 commit comments