Toolbox-XToolbox-X

Pick Object Fields

Creates a new object containing only the specified properties from a source object.

pickFields

The pickFields function creates a new object containing only the specified properties from a source object, preserving accurate TypeScript types.

Function Signature

function pickFields<T extends GenericObject, U extends keyof T>(
  source: T,
  keys: U[]
): { [K in U]: T[K] }

Parameters

  • source (T): The source object to pick properties from.
  • keys (U[]): An array of property keys to select.

Return Value

  • { [K in U]: T[K] }: A new object containing only the specified properties.

Example Usage

playground.ts

Notes

  • This function operates on top-level properties only. It does not support deep picking or dot-notation paths.
  • It is non-destructive and returns a new object without mutating the original source.

Aliases

The following aliases can be used for the pickFields function:

  • pickObjectFields

See Also

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

On this page