export type Omit = Pick>; declare const File: any; /** * Type-safe omit function - returns a new object which omits the specified keys. */ export function omit(obj: T, keysToOmit: K[]): Omit; export function omit(obj: T, keysToOmit: string[], recursive: boolean): T; export function omit(obj: T, keysToOmit: string[], recursive: boolean = false): T { if ((recursive && !isObject(obj)) || isFileObject(obj)) { return obj; } if (recursive && Array.isArray(obj)) { return obj.map((item: any) => omit(item, keysToOmit, true)); } return Object.keys(obj).reduce((output: any, key) => { if (keysToOmit.includes(key)) { return output; } if (recursive) { return {...output, [key]: omit((obj as any)[key], keysToOmit, true)}; } return {...output, [key]: (obj as any)[key]}; }, {} as Omit); } function isObject(input: any): input is object { return typeof input === 'object' && input !== null; } /** * When running in the Node environment, there is no native File object. */ function isFileObject(input): boolean { if (typeof File === 'undefined') { return false; } else { return input instanceof File; } }