Skip to content

Instantly share code, notes, and snippets.

@rasmusmerzin
Created April 23, 2026 13:48
Show Gist options
  • Select an option

  • Save rasmusmerzin/5e0c1f653f1d336a2d835be791f1a8ae to your computer and use it in GitHub Desktop.

Select an option

Save rasmusmerzin/5e0c1f653f1d336a2d835be791f1a8ae to your computer and use it in GitHub Desktop.
export function mapRecord<K extends string, V1, V2>(
input: Record<K, V1>,
mapper: (value: V1, key: K) => V2,
): Record<K, V2> {
const entries = Object.entries(input).map(([key, value]) => [key, mapper(value as V1, key as K)]);
return Object.fromEntries(entries);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment