/** * Returns new object with copied all properties without these specified. * * @param {Object} object - source object * @param {Array.} props - properties to skip * @example * omit({ name: "Jack", age: 69 }, ["age", "title"]); * // { name: "Jack" } * @example * omit(["hello", "world"], [0]); * // { 1: "world" } * @returns {Object} - new object without given properties */ const omit = ( object: T | undefined, props: K[] ): T extends null ? { [key: string]: never } : Omit => { if (object == null) { // @ts-expect-error TS can't handle implementation of dynamic return types yet return {}; } if (!props.length) { // @ts-expect-error TS can't handle implementation of dynamic return types yet return { ...object, }; } const propsToOmit = props.map(String); const result = {}; for (const key in object) { if (!propsToOmit.includes(key)) { (result as T)[key] = object[key]; } } // @ts-expect-error TS can't handle implementation of dynamic return types yet return result as Omit; }; export { omit };