Skip to main content

omit

omit() function

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

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

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

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

declare function omit<T extends object, U extends AsyncIterable<keyof T>>(iterable: U): (obj: T) => Promise<Omit<T, IterableInfer<U>>>;

Example

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