misc-utils.ts 637 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10
// TODO: A lot of this stuff could probably live in core-utils instead.
// Review this file eventually for stuff that could go into core-utils.

/**
 * Returns a copy of the given object ({ ...obj }) with the given keys omitted.
 *
 * @param obj Object to return with the keys omitted.
 * @param keys Keys to omit from the returned object.
 * @returns A copy of the given object with the given keys omitted.
 */
11 12 13 14
export const omit = <T extends object, K extends string | number | symbol>(
  obj: T,
  ...keys: K[]
): Omit<T, K> => {
15 16
  const copy = { ...obj }
  for (const key of keys) {
17
    delete copy[key as string]
18 19 20
  }
  return copy
}