Package: effect
Module: Struct
Renames keys in a struct using a static { oldKey: newKey } mapping. Keys
not mentioned in the mapping are copied unchanged.
When to use
Use when you need simple, declarative key renaming without custom logic.
Details
For computed key names, use evolveKeys instead.
Example (Renaming keys)
import { pipe, Struct } from "effect"
const result = pipe(
{ firstName: "Alice", lastName: "Smith", age: 30 },
Struct.renameKeys({ firstName: "first", lastName: "last" })
)
console.log(result) // { first: "Alice", last: "Smith", age: 30 }
See
evolveKeys – rename keys using functionsevolveEntries – rename keys and transform valuesSignature
declare const renameKeys: { <S extends object, const M extends { readonly [K in keyof S]?: PropertyKey; }>(mapping: M): (self: S) => { [K in keyof S as K extends keyof M ? M[K] extends PropertyKey ? M[K] : K : K]: S[K]; }; <S extends object, const M extends { readonly [K in keyof S]?: PropertyKey; }>(self: S, mapping: M): { [K in keyof S as K extends keyof M ? M[K] extends PropertyKey ? M[K] : K : K]: S[K]; }; }
Since v4.0.0