From b3c62733704f5df8a1fdc39aad9a669bfd95f234 Mon Sep 17 00:00:00 2001 From: James P Date: Fri, 19 Apr 2024 12:21:27 -0500 Subject: [PATCH] Added pick and omit overloads --- src/objects.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/objects.ts b/src/objects.ts index d28c94c..33b083f 100644 --- a/src/objects.ts +++ b/src/objects.ts @@ -5,10 +5,14 @@ export function filterObject(object: O, pred return Object.fromEntries(entries.filter(([key, value]) => predicate(key, value))); } +export function pick(object: T, ...keys: readonly K[]): Pick; +export function pick(object: T, ...keys: readonly (readonly K[])[]): Pick; export function pick(object: T, ...keys: readonly K[] | readonly (readonly K[])[]): Pick { return filterObject>(object, (key: K) => keys.flat().includes(key)); } +export function omit(object: T, ...keys: readonly K[]): Omit; +export function omit(object: T, ...keys: readonly (readonly K[])[]): Omit; export function omit(object: T, ...keys: readonly K[] | readonly (readonly K[])[]): Omit { return filterObject>(object, (key: K) => !keys.flat().includes(key)); }