Skip to content

Commit 082b90d

Browse files
committed
Make map work with strict flag
1 parent fd696d6 commit 082b90d

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

packages/util/src/obj.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
* limitations under the License.
1616
*/
1717

18-
type Keys<T> = Extract<keyof T, string>;
19-
type Values<T> = T[keyof T];
20-
2118
export function contains<T extends object>(obj: T, key: keyof T): boolean {
2219
return Object.prototype.hasOwnProperty.call(obj, key);
2320
}
@@ -42,16 +39,16 @@ export function isEmpty(obj: object): obj is {} {
4239
return true;
4340
}
4441

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,
4845
contextObj?: unknown
49-
): U {
50-
const res: Partial<U> = {};
46+
): { [key in K]: U } {
47+
const res: Partial<{ [key in K]: U }> = {};
5148
for (const key in obj) {
5249
if (Object.prototype.hasOwnProperty.call(obj, key)) {
5350
res[key] = fn.call(contextObj, obj[key], key, obj);
5451
}
5552
}
56-
return res as U;
53+
return res as { [key in K]: U };
5754
}

0 commit comments

Comments
 (0)