JS Built-ins
TypeScriptintermediate

Utility Types β€” Omit<T, K>

πŸ“– Usage Example
type WithoutId = Omit<{ id: number; name: string; age: number }, 'id'>
// WithoutId = { name: string; age: number }

Omit<T, K> removes the listed keys from a type, leaving all other properties intact.

Utility Types: Omit<T, K>

Omit<T, K> removes the keys K from type T.

Challenge: Implement omitKeys<T extends object, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>.

omitKeys({ a: 1, b: 2, c: 3 }, ['b'])  // β†’ { a: 1, c: 3 }
πŸ’‘ Hints (1)
  • β€’ Copy the object, then delete the unwanted keys.