Created
February 27, 2019 07:39
-
-
Save sergeyt/3feea098528dbcfa1d2610b7d163e7e9 to your computer and use it in GitHub Desktop.
generic map object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mapObject<K extends keyof any, T, TResult>(obj: Record<K, T>, makeResult: (val: T, key?: K) => TResult): Record<K, TResult> { | |
return (Object.keys(eventMap) as K[]).reduce( | |
(acc, key) => ({ | |
...acc, | |
[key]: makeResult(obj[key]), | |
}), | |
{} as Record<K, TResult> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment