Omit properties function typescript

Hey, I'm trying to write helper function to easily omit some properties form my object, but I can't really get correct return type that omits properties i passed throught. Right now it returns object that has type of the same object i pass in parameter.

export function omit<T extends object, U extends keyof T>(obj: T, ...props: U[]) {
  const result = { ...obj };
  props.forEach(function (prop) {
    delete result[prop];
  });

  return result as Omit<T, U>;
}

omit<typeof input, keyof typeof input>(input, "owner", "type");
Was this page helpful?