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
At a glance
- Purpose
- Static types for JavaScript
- File extension
- .ts ยท .tsx
- Runs in
- Compiled to JavaScript
- Usually used with
- JavaScript and its ecosystem
Specifications & further reading
Related TypeScript documentation
Partial<T> and Required<T>
Partial<T> constructs a new type with every property of T marked optional - useful for representing partial updates, like a PATCH request body. Required<T> does the opposite, making every property mandatory even if the original type had optional ones, useful for ensuring a fully-populated object at a specific point in your code.Record<K, V>
Record<Keys, ValueType> constructs an object type with a specific set of keys, all mapped to the same value type. It is the concise, standard way to type dictionary-like objects, and is often clearer than writing an equivalent index signature by hand.Readonly<T>
Readonly<T> constructs a new type where every property of T is marked readonly, preventing reassignment after the object is created. It is a shallow transformation - nested objects within a Readonly<T> are not automatically deep-frozen, only the top-level properties are protected from reassignment.ReturnType<T> and Parameters<T>
ReturnType<T> extracts the return type of a function type, and Parameters<T> extracts its parameter types as a tuple. Both are especially useful for deriving types from functions you do not directly control, like third-party library functions, without manually duplicating their signatures.
Partial<T> constructs a new type with every property of T marked optional - useful for representing partial updates, like a PATCH request body. Required<T> does the opposite, making every property mandatory even if the original type had optional ones, useful for ensuring a fully-populated object at a specific point in your code.Record<K, V>
Record<Keys, ValueType> constructs an object type with a specific set of keys, all mapped to the same value type. It is the concise, standard way to type dictionary-like objects, and is often clearer than writing an equivalent index signature by hand.Readonly<T>
Readonly<T> constructs a new type where every property of T is marked readonly, preventing reassignment after the object is created. It is a shallow transformation - nested objects within a Readonly<T> are not automatically deep-frozen, only the top-level properties are protected from reassignment.ReturnType<T> and Parameters<T>
ReturnType<T> extracts the return type of a function type, and Parameters<T> extracts its parameter types as a tuple. Both are especially useful for deriving types from functions you do not directly control, like third-party library functions, without manually duplicating their signatures.