Skip to content

Utility Types in TypeScript

Built-in type transformations: Partial, Required, Pick, Omit, Record, Readonly, and more.

What you'll learn

  • How Partial<T> and Required<T> toggle optional properties
  • Using Pick<T, K> and Omit<T, K> to select or exclude keys
  • Record<K, V> for keyed maps and Readonly<T> for immutability
  • ReturnType<T> and Parameters<T> for function type extraction

Concept

Property Modifiers

Partial<T> makes every property of T optional — useful for update/patch operations where you only send changed fields. Required<T> does the opposite, making all properties required. Readonly<T> makes every property readonly, preventing mutation. These three are the most commonly used utility types and are built from mapped types internally.

Key Selection

Pick<T, K> creates a new type with only the keys K from T. Omit<T, K> creates a type with all keys except K. These are invaluable for creating focused types from a large base type: type UserSummary = Pick<User, "id" | "name"> gives you a lightweight view with just ID and name, while type UserUpdate = Omit<User, "id" | "createdAt"> excludes fields that should not be edited.

Function and Record Types

Record<K, V> creates an object type with keys K and values V — cleaner than an index signature. ReturnType<T> extracts the return type of a function type, and Parameters<T> extracts the parameter types as a tuple. These let you derive types from existing functions without duplicating their signatures, keeping your types in sync with your implementations automatically.

Example

              interface User {
  id: number;
  name: string;
  email: string;
  role: string;
}

// Partial — all properties become optional (for updates).
type UserUpdate = Partial<User>;
const patch: UserUpdate = { name: "New Name" };

// Pick — select only specific keys.
type UserSummary = Pick<User, "id" | "name">;
const summary: UserSummary = { id: 1, name: "Alice" };

// Omit — exclude specific keys.
type CreateUser = Omit<User, "id">;
const newUser: CreateUser = { name: "Bob", email: "b@x.com", role: "user" };

// Record — typed map with known keys.
type Roles = Record<"admin" | "editor" | "viewer", number>;
const counts: Roles = { admin: 2, editor: 5, viewer: 100 };

// ReturnType — extract a function's return type.
function createUser() {
  return { id: 1, name: "Alice" };
}
type CreatedUser = ReturnType<typeof createUser>;

console.log(patch, summary, newUser, counts);
            

Partial/Required/Readonly modify properties. Pick/Omit select keys. Record creates keyed maps. ReturnType/Parameters extract function types. These are built from mapped and conditional types.

Try it

Common mistakes

The mistake

Using Partial<T> for create operations where all fields are required

The fix

Partial makes all fields optional, which is wrong for creation. Use Omit<T, 'id'> to exclude only the auto-generated field, keeping the rest required.

The mistake

Re-declaring types instead of using Pick and Omit to derive them

The fix

Derive focused types from a base type with Pick and Omit. This keeps them in sync — if the base type changes, the derived types update automatically.

Practice Utility Types in TypeScript

16 exercises

Practice Utility Types in TypeScript

Look up unfamiliar terms

A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.

View glossary

Build real projects

Apply what you learned by building guided projects with starter code and solutions.

View projects

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors