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 offieldMap) to existing keys insource(as values offieldMap).
Return Value
{ [K in keyof Target]: Source[Target[K]] }: A new object structured with the keys offieldMapand the corresponding values fromsource.
Example Usage
playground.ts
Notes
- This function performs a shallow transformation only.
- Keys omitted from
fieldMapwill not exist in the returned object.
Aliases
The following aliases can be used for the remapFields function:
remapObjectFields
See Also
- pickFields - Select specific object fields without renaming.
- deleteFields - Exclude specific object fields.
Last updated: Sun, Jun 14, 2026 07:06:16AM (UTC)
