File tree 2 files changed +8
-6
lines changed
2 files changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -109,8 +109,8 @@ declare namespace Filesize {
109
109
}
110
110
111
111
// Result type inference from the output option
112
- interface ResultTypeMap {
113
- array : [ number , string ] ;
112
+ interface ResultTypeMap < O > {
113
+ array : [ O extends { precision : number } ? string : number , string ] ;
114
114
exponent : number ;
115
115
object : {
116
116
value : number ,
@@ -120,12 +120,12 @@ declare namespace Filesize {
120
120
} ;
121
121
string : string ;
122
122
}
123
- type DefaultOutput < O extends Options > = Exclude < O [ "output" ] , keyof ResultTypeMap > extends never ? never : "string"
124
- type CanonicalOutput < O extends Options > = Extract < O [ "output" ] , keyof ResultTypeMap > | DefaultOutput < O >
123
+ type DefaultOutput < O extends Options > = Exclude < O [ "output" ] , keyof ResultTypeMap < O > > extends never ? never : "string"
124
+ type CanonicalOutput < O extends Options > = Extract < O [ "output" ] , keyof ResultTypeMap < O > > | DefaultOutput < O >
125
125
126
126
interface Filesize {
127
127
( bytes : number ) : string ;
128
- < O extends Options > ( bytes : number , options : O ) : ResultTypeMap [ CanonicalOutput < O > ] ;
129
- partial : < O extends Options > ( options : O ) => ( ( bytes : number ) => ResultTypeMap [ CanonicalOutput < O > ] ) ;
128
+ < O extends Options > ( bytes : number , options : O ) : ResultTypeMap < O > [ CanonicalOutput < O > ] ;
129
+ partial : < O extends Options > ( options : O ) => ( ( bytes : number ) => ResultTypeMap < O > [ CanonicalOutput < O > ] ) ;
130
130
}
131
131
}
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import filesize from "../filesize";
8
8
9
9
function shouldBeString ( x : string ) { }
10
10
function shouldBeNumberUnitPair ( x : [ number , string ] ) { }
11
+ function shouldBeStringUnitPair ( x : [ string , string ] ) { }
11
12
function shouldBeNumber ( x : number ) { }
12
13
13
14
type FilesizeObject = {
@@ -28,6 +29,7 @@ shouldBeString(filesize(123, {}));
28
29
shouldBeString ( filesize ( 123 , { output : undefined } ) ) ;
29
30
shouldBeString ( filesize ( 123 , { output : "string" } ) ) ;
30
31
shouldBeNumberUnitPair ( filesize ( 123 , { output : "array" } ) ) ;
32
+ shouldBeStringUnitPair ( filesize ( 123 , { precision : 2 , output : "array" } ) ) ;
31
33
shouldBeNumber ( filesize ( 123 , { output : "exponent" } ) ) ;
32
34
shouldBeObject ( filesize ( 123 , { output : "object" } ) ) ;
33
35
You can’t perform that action at this time.
0 commit comments