From 9e42bec98afe86fce2f2e38f34ebe8ce7258791d Mon Sep 17 00:00:00 2001 From: ryan-zayne Date: Wed, 9 Oct 2024 23:53:36 +0100 Subject: [PATCH] =?UTF-8?q?refactor=20=E2=99=BB=EF=B8=8F:=20=20omitkeys=20?= =?UTF-8?q?and=20pickkeys=20functions.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Refactor the omitKeys function to use a generic type to represent the keys to omit. - Refactor the pickKeys function to return the correct type. --- .changeset/big-spies-turn.md | 8 ++++++++ src/core/omitKeys.ts | 8 +++++--- src/core/pickKeys.ts | 8 +++++--- 3 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 .changeset/big-spies-turn.md diff --git a/.changeset/big-spies-turn.md b/.changeset/big-spies-turn.md new file mode 100644 index 0000000..24fe398 --- /dev/null +++ b/.changeset/big-spies-turn.md @@ -0,0 +1,8 @@ +--- +"@zayne-labs/toolkit": patch +--- + +refactor ♻️: omitkeys and pickkeys functions. + +- Refactor the omitKeys function to use a generic type to represent the keys to omit. +- Refactor the pickKeys function to return the correct type. diff --git a/src/core/omitKeys.ts b/src/core/omitKeys.ts index 632ae9b..60d2b49 100644 --- a/src/core/omitKeys.ts +++ b/src/core/omitKeys.ts @@ -1,5 +1,7 @@ import type { AnyObject } from "@/type-helpers"; +type OmitKeys = Omit; + export const omitKeys = >( initialObject: TObject, keysToOmit: TOmitArray @@ -14,7 +16,7 @@ export const omitKeys = ; + return updatedObject as OmitKeys; }; export const omitKeysWithReduce = < @@ -34,7 +36,7 @@ export const omitKeysWithReduce = < return accumulator; }, {}); - return updatedObject as Omit; + return updatedObject as OmitKeys; }; export const omitKeysWithFilter = < @@ -52,5 +54,5 @@ export const omitKeysWithFilter = < const updatedObject = Object.fromEntries(arrayFromFilteredObject); - return updatedObject as Omit; + return updatedObject as OmitKeys; }; diff --git a/src/core/pickKeys.ts b/src/core/pickKeys.ts index 6e32b6d..d30bbda 100644 --- a/src/core/pickKeys.ts +++ b/src/core/pickKeys.ts @@ -1,5 +1,7 @@ import type { AnyObject } from "@/type-helpers"; +type PickKeys = Pick; + export const pickKeys = >( initialObject: TObject, keysToPick: TPickArray @@ -14,7 +16,7 @@ export const pickKeys = ; + return updatedObject as PickKeys; }; export const pickKeysWithReduce = < @@ -34,7 +36,7 @@ export const pickKeysWithReduce = < return accumulator; }, {}); - return updatedObject as Pick; + return updatedObject as PickKeys; }; export const pickKeysWithFilter = < @@ -50,5 +52,5 @@ export const pickKeysWithFilter = < const updatedObject = Object.fromEntries(arrayFromFilteredObject); - return updatedObject as Pick; + return updatedObject as PickKeys; };