Created
September 21, 2024 23:57
-
-
Save fnimick/24a559436af317374694fe4d2d2046ee 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
import { Record } from "effect"; | |
function renameKeys<T extends Record<string | symbol, unknown>, M extends Record<string, string>>( | |
input: T, | |
map: M, | |
): { [Property in keyof T as Property extends keyof M ? M[Property] : Property]: T[Property] } { | |
return Record.mapKeys(input, (key) => (key in map ? map[key as keyof M] : key)) as any; | |
} | |
function renameKey< | |
T extends Record<string | symbol, unknown>, | |
K extends keyof T, | |
K2 extends string, | |
>(input: T, key: K, newKey: K2) { | |
return renameKeys(input, { [key]: newKey } as Record<K, K2>); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment