Skip to content

omit() function

Returns a partial copy of an object omitting the keys specified.

Signature:

typescript
declare function omit<T extends object, U extends Iterable<keyof T>>(iterable: U, obj: T): Omit<T, IterableInfer<U>>;

Example

ts
const person = {
  name: "james",
  age: 40,
  numberOfKids: 2,
  team: "Software Development",
  preferredLanguage: "Rust",
};

const dad = omit(["team", "preferredLanguage"], person);
// { name: "james", age: 40, numberOfKids: 2 }

const developer = omit(["age", "numberOfKids"], person);
// { name: "james", team: "Software Development", preferredLanguage: "Rust" }

// with pipe
pipe(
 person,
 omit(["team", "preferredLanguage"]),
);

// if you want to use AsyncIterable as the list of property names
const anonymous = await omit(toAsync(["name"] as const), person);

see pipe, toAsync, pick,

Open Source Code

Released under the Apache-2.0 License.