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; };