omit.ts 468 B

12345678910111213
  1. export type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
  2. /**
  3. * Type-safe omit function - returns a new object which omits the specified keys.
  4. */
  5. export function omit<T extends object, K extends keyof T>(obj: T, keysToOmit: K[]): Omit<T, K> {
  6. return Object.keys(obj).reduce((output: any, key) => {
  7. if (keysToOmit.includes(key as K)) {
  8. return output;
  9. }
  10. return { ...output, [key]: (obj as any)[key] };
  11. }, {} as Omit<T, K>);
  12. }