Created
July 30, 2024 04:36
-
-
Save misebox/e041cc22c15a2095861a75500ad7d2d9 to your computer and use it in GitHub Desktop.
オブジェクト変換コードの見た目の複雑さを少し減らす関数
This file contains 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
type Mapper<K, V, NK, NV> = (entry: [K, V]) => [NK, NV]; | |
function mapEntries<K extends string, V, NK extends string, NV>( | |
obj: Record<K, V>, | |
mapper: Mapper<K, V, NK, NV> | |
): Record<NK, NV> { | |
return Object.fromEntries( | |
Object.entries(obj).map(mapper) | |
) as Record<NK, NV>; | |
} |
Author
misebox
commented
Jul 30, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment