Know if you're actually ready. Take the TypeScript quiz → get your AI readiness report.Take the free test →

Study guide · TypeScript

TypeScript Utility Types: Partial, Pick, Omit, Record

This page contains affiliate links. We may earn a commission at no extra cost to you.

Utility types transform existing types into new ones. These save you from writing repetitive type definitions.

Partial, Required, and Readonly

These three transform all properties in a type at once.

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

// All properties become optional
type PartialUser = Partial<User>;
// { id?: string; name?: string; email?: string; }

// All properties become required
type RequiredUser = Required<PartialUser>;
// { id: string; name: string; email: string; }

// All properties become readonly
type ReadonlyUser = Readonly<User>;
// { readonly id: string; readonly name: string; ... }

// Common pattern: update function accepts partial updates
function updateUser(id: string, updates: Partial<User>) {
    return fetch(`/users/${id}`, {
        method: 'PATCH',
        body: JSON.stringify(updates),
    });
}

Pick and Omit

Pick creates a type with only the specified properties. Omit creates a type without them.

interface User {
    id: string;
    name: string;
    email: string;
    password: string;
    createdAt: Date;
}

// Include only specific properties
type PublicUser = Pick<User, "id" | "name" | "email">;
// { id: string; name: string; email: string; }

// Exclude specific properties
type UserWithoutPassword = Omit<User, "password">;
// { id: string; name: string; email: string; createdAt: Date; }

// Common pattern: API response type
type UserResponse = Omit<User, "password">;

Record

Record creates an object type with specific key and value types.

// Record<Keys, Values>
type ScoreMap = Record<string, number>;
const scores: ScoreMap = { alice: 95, bob: 87 };

// With literal key union
type Role = "admin" | "user" | "guest";
type Permissions = Record<Role, string[]>;

const perms: Permissions = {
    admin: ["read", "write", "delete"],
    user:  ["read", "write"],
    guest: ["read"],
};

// Useful pattern: index signature alternative
type CacheEntry = { value: string; expires: number };
type Cache = Record<string, CacheEntry>;

Exclude, Extract, NonNullable, ReturnType

These utility types operate on union types and functions.

type A = Exclude<string | number | boolean, boolean>;
// string | number

type B = Extract<string | number | boolean, string | boolean>;
// string | boolean

type C = NonNullable<string | null | undefined>;
// string

function fetchData() { return { id: 1, name: "Alice" }; }
type D = ReturnType<typeof fetchData>;
// { id: number; name: string }

// Parameters extracts argument types
function login(email: string, password: string) {}
type E = Parameters<typeof login>;
// [email: string, password: string]
Exam tipPartial<T> is the most commonly used utility type in real code — it's used everywhere for update/patch functions. Know all five: Partial, Required, Readonly, Pick, and Omit. They're all tested.

Want a person to help?

Struggling with TypeScript? Work 1:1 with a vetted TypeScript tutor on Wyzant. (affiliate link)

Find a TypeScript tutor →
← All TypeScript guides