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
- pickFieldsByCondition - Conditionally select object fields.
- deleteFields - Remove specific object fields.
- remapFields - Rename object keys.
Last updated: Sun, Jun 14, 2026 07:06:16AM (UTC)
