Toolbox-XToolbox-X

Remap Object Fields

Transforms an object's structure by mapping properties to new names according to a provided field mapping.

remapFields

The remapFields function maps properties of an object to new key names based on a mapping schema, preserving value types in the returned object.

Function Signature

function remapFields<Source extends GenericObject, Target extends Record<string, keyof Source>>(
  source: Source,
  fieldMap: Target
): { [K in keyof Target]: Source[Target[K]] }

Parameters

  • source (Source): The source object to remap.
  • fieldMap (Target): An object mapping new target keys (as keys of fieldMap) to existing keys in source (as values of fieldMap).

Return Value

  • { [K in keyof Target]: Source[Target[K]] }: A new object structured with the keys of fieldMap and the corresponding values from source.

Example Usage

playground.ts

Notes

  • This function performs a shallow transformation only.
  • Keys omitted from fieldMap will not exist in the returned object.

Aliases

The following aliases can be used for the remapFields function:

  • remapObjectFields

See Also

Last updated: Sun, Jun 14, 2026 07:06:16AM (UTC)

On this page