File tree Expand file tree Collapse file tree 1 file changed +6
-9
lines changed Expand file tree Collapse file tree 1 file changed +6
-9
lines changed Original file line number Diff line number Diff line change 15
15
* limitations under the License.
16
16
*/
17
17
18
- type Keys < T > = Extract < keyof T , string > ;
19
- type Values < T > = T [ keyof T ] ;
20
-
21
18
export function contains < T extends object > ( obj : T , key : keyof T ) : boolean {
22
19
return Object . prototype . hasOwnProperty . call ( obj , key ) ;
23
20
}
@@ -42,16 +39,16 @@ export function isEmpty(obj: object): obj is {} {
42
39
return true ;
43
40
}
44
41
45
- export function map < T extends object , V , U extends { [ key in keyof T ] : V } > (
46
- obj : T ,
47
- fn : ( value : Values < T > , key : Keys < T > , obj : T ) => V ,
42
+ export function map < K extends string , V , U > (
43
+ obj : { [ key in K ] : V } ,
44
+ fn : ( value : V , key : K , obj : { [ key in K ] : V } ) => U ,
48
45
contextObj ?: unknown
49
- ) : U {
50
- const res : Partial < U > = { } ;
46
+ ) : { [ key in K ] : U } {
47
+ const res : Partial < { [ key in K ] : U } > = { } ;
51
48
for ( const key in obj ) {
52
49
if ( Object . prototype . hasOwnProperty . call ( obj , key ) ) {
53
50
res [ key ] = fn . call ( contextObj , obj [ key ] , key , obj ) ;
54
51
}
55
52
}
56
- return res as U ;
53
+ return res as { [ key in K ] : U } ;
57
54
}
You can’t perform that action at this time.
0 commit comments