ComparisonComparisons

Pick vs Omit

Pick<Type, Keys> selects only the given fields from a type, while Omit<Type, Keys> copies every field except the given ones.

On this page

Side-by-side comparison

#

Example

#
TypeScript
interface User {
  id: number
  name: string
  passwordHash: string
}

type PublicUser = Pick<User, 'id' | 'name'>
type NewUser = Omit<User, 'id'>

const publicUser: PublicUser = { id: 1, name: 'Emma' }
const newUser: NewUser = { name: 'Jack', passwordHash: 'xyz' }

console.log(publicUser, Object.keys(newUser))
Result
{ id: 1, name: 'Emma' } ['name', 'passwordHash']

Definition and usage

#

Both utility types build a new object type from an existing one, without rewriting it from scratch. They work on the same arguments: a source type and a union of field names.

They differ in which fields remain. Pick<User, "id" | "name"> keeps only the listed fields, and everything else is dropped. Omit<User, "passwordHash"> does the opposite: it keeps everything except the listed fields. Pick checks that the given keys exist on the source type, while Omit doesn’t, so a typo in the name of a field you’re removing won’t be reported by the compiler.

Choose Pick when it’s easier to list the few fields you want to keep, for example for a public profile view. Choose Omit when it’s easier to list the few fields to drop, for example form data without the fields generated by the server. You can also combine either one with the & intersection to add a field with a different type.

Syntax

#
Syntax
type New = Pick<Type, "field1" | "field2">
type Other = Omit<Type, "field1">

More examples

#
Omit doesn’t check field names
TypeScript
interface Task {
  id: number
  title: string
}

type NewTask = Omit<Task, 'id' | 'ttile'>

const task: NewTask = { title: 'Learning Python' }
console.log(task)
Result
{ title: 'Learning Python' }

The typo ttile doesn’t exist on Task, yet the compiler reports nothing, because Omit doesn’t check whether the given keys exist on the source type.

Pick checks field names
TypeScript
interface Task {
  id: number
  title: string
}

type TaskPreview = Pick<Task, 'id' | 'titel'>
// Error: Type '"titel"' does not satisfy the constraint 'keyof Task'.

Good practices

#
  • When most fields should stay and only a few are dropped, choose Omit. When only a few fields remain, choose Pick.
  • Types derived with Pick and Omit update themselves automatically when the source type changes, so you avoid duplicating definitions.
  • Combine them with the & intersection to change the type of one field: Omit<User, "id"> & { id: string }.

Related entries

#

Spotted a mistake or missing an example? Write to us.