Skip to main content
@spa-tools/utilities

omit()

The omit<T>() function is similar to the TypeScript Omit utility type, but it is used at runtime to return a new object with one or more properties omitted from the provided object.

The generic T type is used to define the type of the object that is omitted from.

Usage

import { omit } from '@spa-tools/utilities';

const person = {
address: {
city: 'New York',
country: 'USA',
},
childrenAges: [8, 10],
id: 1,
name: 'John',
};

const newPerson = omit(person, 'id', 'childrenAges');
console.log(newPerson);
// -->
// {
// address: {
// city: 'New York',
// country: 'USA'
// },
// name: 'John'
// }

Arguments

NameTypeDescription
objTThe object to omit from
...keysstring[]A param list of keys to omit

Returns

Returns object as type of Omit<T, keyof T>.