Omit
VerifiedReturns a new object without the given keys, fully typed.
- object
- omit
Install
npx shadcn@latest add https://quicksnip.dev/r/omit.jsonCode
/** Returns a new object without the given keys. */
export function omit<T extends object, K extends keyof T>(obj: T, keys: readonly K[]): Omit<T, K> {
const result = { ...obj };
for (const key of keys) delete result[key];
return result;
}Usage
omit({ id: 1, name: "Ada", password: "x" }, ["password"]); // { id: 1, name: "Ada" }