Skip to content

@kaelyx/ts-kit / object / omit

Function: omit() ​

omit<T, K>(object, keys): Omit<T, K>

Defined in: object/omit/omit.ts:24

Creates a new object by copying the source object without the specified keys.

Behaves like a rest pattern: omit(object, ['a']) produces the same object as rest in const { a, ...rest } = object. Only own enumerable properties (including symbol keys) are copied. Inherited properties (including class methods and getters) and non-enumerable properties are not included, and getters are read so that their current value is copied.

Type Parameters ​

T ​

T extends object

K ​

K extends string | number | symbol

Parameters ​

object ​

T

The source object. An empty object will result in an empty output.

keys ​

readonly K[]

The keys to leave out. An empty array will result in a shallow copy of the source object.

Returns ​

Omit<T, K>

A new object containing every own enumerable property of the input object except the specified keys.

Example ​

ts
omit({ a: 1, b: 2 }, ['a']) // result: { b: 2 }
omit({ a: 1, b: 2, c: 3 }, ['a', 'c']) // result: { b: 2 }
omit({ a: 1, b: undefined }, ['b']) // result: { a: 1 }
omit({ a: 1, b: 2 }, []) // result: { a: 1, b: 2 }