Home/TypeScript Utility Types
TypeScript Utility Types: Partial, Pick, Omit & More
TypeScript ships with over a dozen built-in utility types that transform existing types without writing boilerplate. This guide covers every utility type with real code examples so you can reach for the right one immediately.
All examples use this base interface:
interface User {
id: number;
name: string;
email: string;
password: string;
role: "admin" | "user";
createdAt: Date;
}Object-Transforming Utilities
Partial<T>
Makes all properties optional. Perfect for PATCH endpoints where the client sends only changed fields.
type PartialUser = Partial<User>;
// { id?: number; name?: string; email?: string; password?: string; role?: "admin" | "user"; createdAt?: Date }
async function updateUser(id: number, patch: Partial<User>): Promise<User> {
// Only the fields provided in 'patch' will be updated
return { ...currentUser, ...patch };
}Required<T>
The inverse of Partial — removes all optional markers, making every property required.
interface Config {
host?: string;
port?: number;
ssl?: boolean;
}
type StrictConfig = Required<Config>;
// { host: string; port: number; ssl: boolean }
// TypeScript now errors if any field is missingReadonly<T>
Makes all properties read-only. Assignment to any property is a compile-time error.
const user: Readonly<User> = { id: 1, name: "Alice", email: "alice@example.com", password: "secret", role: "user", createdAt: new Date() };
user.name = "Bob"; // Error: Cannot assign to 'name' because it is a read-only propertyField Selection Utilities
Pick<T, K>
Creates a type by selecting a subset of keys from T. Great for DTOs and API response shapes.
type PublicUser = Pick<User, "id" | "name" | "email">;
// { id: number; name: string; email: string }
// password and role are excluded — safe to return from an API
type UserPreview = Pick<User, "id" | "name">;
// Minimal shape for list viewsOmit<T, K>
Creates a type by removing specified keys from T. The complement of Pick.
type SafeUser = Omit<User, "password">;
// All User fields except password
type NewUser = Omit<User, "id" | "createdAt">;
// Shape for creating a new user — id and createdAt are generated server-sideRecord<K, V>
Creates an object type with keys of type K and values of type V. Excellent for lookup tables and maps.
// All keys must be present when K is a union
type RoleConfig = Record<"admin" | "user" | "guest", { canRead: boolean; canWrite: boolean }>;
const roles: RoleConfig = {
admin: { canRead: true, canWrite: true },
user: { canRead: true, canWrite: false },
guest: { canRead: true, canWrite: false },
};
// Dynamic key lookups
const cache: Record<string, User> = {};
cache["user:1"] = { id: 1, name: "Alice", email: "a@a.com", password: "", role: "user", createdAt: new Date() };Union Type Utilities
type ABC = "a" | "b" | "c" | "d";
// Exclude removes members from a union
type BC = Exclude<ABC, "a" | "d">; // "b" | "c"
// Extract keeps only matching members
type AD = Extract<ABC, "a" | "d" | "z">; // "a" | "d"
// NonNullable removes null and undefined
type MaybeString = string | null | undefined;
type JustString = NonNullable<MaybeString>; // stringFunction Utilities
async function fetchUser(id: number): Promise<User> {
const res = await fetch(`/api/users/${id}`);
return res.json();
}
// ReturnType extracts the return type of a function
type FetchUserReturn = ReturnType<typeof fetchUser>; // Promise<User>
type ResolvedUser = Awaited<ReturnType<typeof fetchUser>>; // User
// Parameters extracts the parameter types as a tuple
type FetchUserParams = Parameters<typeof fetchUser>; // [id: number]
// ConstructorParameters works the same for class constructors
class EventEmitter {
constructor(private maxListeners: number, private name: string) {}
}
type EmitterArgs = ConstructorParameters<typeof EventEmitter>; // [maxListeners: number, name: string]Frequently Asked Questions
What is Partial<T> in TypeScript?
Partial<T> creates a new type where all properties of T are optional (adds '?' to every property). It is commonly used for update/patch operations where only some fields may be provided.
What is the difference between Pick and Omit?
Pick<T, K> creates a type by selecting only the specified keys K from T. Omit<T, K> creates a type by removing the specified keys. Use Pick for a small subset, Omit when you want almost everything except a few fields.
What is Record<K, V> in TypeScript?
Record<K, V> creates an object type with keys of type K and values of type V. It is equivalent to { [key in K]: V }. Useful for lookup tables and dictionaries. When K is a union of string literals, all those keys are required.
What does ReturnType<T> do in TypeScript?
ReturnType<T> extracts the return type of a function type T. For example, ReturnType<typeof fetchUser> gives the exact type that fetchUser returns without having to repeat or import the return type manually.
What is Awaited<T> in TypeScript?
Awaited<T> (TypeScript 4.5+) recursively unwraps Promise types. Awaited<Promise<string>> gives string. It is useful combined with ReturnType to get the resolved value of an async function.
What is the difference between Exclude and Extract?
Both operate on union types. Exclude<T, U> removes from T all members assignable to U. Extract<T, U> keeps only members of T that are assignable to U. They are inverses of each other.
Try the free JS → TS converter
Paste JavaScript and get TypeScript with type annotations, utility types, and proper interfaces in seconds.
Convert now →From the blog
View all →
May 13, 2026
Convert XML to JSON Online: Complete Guide for Developers (2026)

May 11, 2026
Convert CSV to JSON Online Free (Best Developer Guide 2026)

May 6, 2026
Convert YAML to JSON Online Free (2026 Developer Guide)

Apr 30, 2026
Convert JSON to Zod Schema Online (2026) – Free Tool & Complete Guide

Apr 30, 2026
Top 50 JavaScript to TypeScript Converters (2026) – Free, AI & Online Tools