diff --git a/packages/toolkit/src/core/omitKeys.ts b/packages/toolkit/src/core/omitKeys.ts index 60d2b49..e031ed0 100644 --- a/packages/toolkit/src/core/omitKeys.ts +++ b/packages/toolkit/src/core/omitKeys.ts @@ -56,3 +56,23 @@ export const omitKeysWithFilter = < return updatedObject as OmitKeys; }; + +export const omitKeysWithDelete = < + TObject extends AnyObject, + const TOmitArray extends Array, +>( + initialObject: TObject, + keysToOmit: TOmitArray +) => { + const keysToOmitSet = new Set(keysToOmit); + + const updatedObject = { ...initialObject }; + + for (const key of Object.keys(updatedObject)) { + if (keysToOmitSet.has(key)) { + Reflect.deleteProperty(updatedObject, key); + } + } + + return updatedObject as OmitKeys; +};