Syntax
Pick<Type, Keys>
Omit<Type, Keys>Examples
Pick<T> - Selecting Specific Properties
Deriving a smaller type with just the fields you need.
interface User {
id: number;
name: string;
email: string;
password: string;
}
type UserPreview = Pick<User, "id" | "name">;
// Equivalent to: { id: number; name: string }
const preview: UserPreview = { id: 1, name: "Alice" };Omit<T> - Excluding Specific Properties
A very common real-world case: deriving a "safe" type that excludes sensitive fields.
type PublicUser = Omit<User, "password">;
// Equivalent to: { id: number; name: string; email: string }
function sendToClient(user: User): PublicUser {
const { password, ...publicUser } = user;
return publicUser; // password is excluded, matching the PublicUser type
}Best practices
- Use Pick<T> when you need a smaller type with just a few known fields from a larger interface, keeping both types in sync automatically
- Use Omit<T> especially for excluding sensitive fields (like password or internal IDs) when defining what data is safe to send to a client
- Derive types with Pick/Omit rather than manually rewriting a near-duplicate interface - the derived type stays in sync if the base type changes
- Chain Pick and Omit with other utility types (like Partial<Omit<User, "id">>) for precise, composed type transformations
Runtime & versions
Compiled to JavaScript. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
TypeScript Handbook