export type DeepOmit = T extends Record ? { [P in Exclude]: DeepOmit } : T; export function deepOmit( obj: T, ...keysToOmit: K[] ): DeepOmit { const omitSet = new Set(keysToOmit); if (Array.isArray(obj)) { return obj.map((item) => deepOmit(item, ...keysToOmit), ) as unknown as DeepOmit; } else if (typeof obj === 'object' && obj !== null) { const result: Partial> = {}; for (const [key, value] of Object.entries(obj)) { if (!omitSet.has(key as K)) { result[key as Exclude] = deepOmit( value, ...keysToOmit, ); } } return result as DeepOmit; } return obj as DeepOmit; }