JS Built-ins
TypeScriptintermediate

Utility Types β€” pickByPredicate

πŸ“– Usage Example
pickByPredicate({ a: 1, b: 0, c: 2 }, v => v > 0)
// β†’ { a: 1, c: 2 }

pickByPredicate returns a new object with only the entries whose values satisfy the predicate.

Utility Types: Filter Object Properties

Challenge: Implement pickByPredicate<T extends object>(obj: T, pred: (v: T[keyof T]) => boolean): Partial<T> keeping only the entries where the value passes the predicate.

pickByPredicate({ a: 1, b: 2, c: 3 }, v => v > 1)  // β†’ { b: 2, c: 3 }
πŸ’‘ Hints (1)
  • β€’ Iterate object entries; push only those where pred returns true.