TypeScript utility types let you reshape existing types without duplicating their definitions. This reference shows which utility type to choose for forms, CRUD operations, API payloads, configuration, React props, and event handlers, with copyable examples and a checklist for diagnosing common type errors.
Overview
Utility types are built-in type transformations. Instead of writing a second interface whenever a value changes slightly, you can derive a new type from a trusted model. This keeps related types connected as the original model evolves.
For example, a database record may require an id and timestamps, while a create request should omit them. An edit form may accept only a few fields, and a patch request may make every selected field optional. These are different shapes, but they usually belong to the same data model.
type User = {
id: string;
name: string;
email: string;
role: "admin" | "member";
createdAt: Date;
};
type CreateUser = Omit<User, "id" | "createdAt">;
type UpdateUser = Partial<CreateUser>;
type UserSummary = Pick<User, "id" | "name" | "role">;
The main decision is whether you are changing property optionality, selecting properties, excluding properties, restricting values, or deriving a type from a function. Use the smallest transformation that accurately describes the runtime data.
| Utility type | Use it when you need to | Example |
|---|---|---|
Partial<T> | Make every property optional | Partial<User> |
Required<T> | Make every property required | Required<Draft> |
Pick<T, K> | Keep a named subset of properties | Pick<User, "id" | "name"> |
Omit<T, K> | Remove named properties | Omit<User, "id"> |
Record<K, V> | Map keys to one value type | Record<Role, string> |
Readonly<T> | Prevent direct property reassignment | Readonly<Config> |
Extract<T, U> | Keep union members assignable to another type | Extract<Status, "open" | "closed"> |
Exclude<T, U> | Remove union members assignable to another type | Exclude<Status, "archived"> |
NonNullable<T> | Remove null and undefined | NonNullable<User> |
ReturnType<F> | Reuse a function's return type | ReturnType<typeof loadUser> |
Awaited<T> | Unwrap promise-like results | Awaited<ReturnType<typeof loadUser>> |
Checklist by scenario
CRUD models and API requests
Start with a complete domain model, then derive transport types according to the API contract. Omit is useful for fields generated by the server, while Pick is useful when an endpoint accepts an explicit small set of fields.
type Product = {
id: string;
name: string;
price: number;
description: string;
createdAt: string;
updatedAt: string;
};
type CreateProduct = Omit<Product, "id" | "createdAt" | "updatedAt">;
type ProductPatch = Partial<Pick<Product, "name" | "price" | "description">>;
type ProductListItem = Pick<Product, "id" | "name" | "price">;
Use Partial<T> for a true patch-style payload where every field may be absent. Do not use it automatically for a create request: making required input optional can hide incomplete data before it reaches validation.
Forms and React props
Forms often begin with a complete model but collect only editable fields. Derive the form values and use Partial only when the form genuinely supports incomplete state.
type Account = {
id: string;
displayName: string;
email: string;
avatarUrl: string | null;
isVerified: boolean;
};
type AccountFormValues = Pick<Account, "displayName" | "avatarUrl">;
type AccountCardProps = Pick<Account, "displayName" | "avatarUrl" | "isVerified"> & {
onEdit: () => void;
};
For component variants, combine utility types with an explicit discriminant rather than making every prop optional. A union can express which props belong together:
type ButtonProps =
| { kind: "link"; href: string; onClick?: never }
| { kind: "button"; onClick: () => void; href?: never };
Configuration and lookup tables
Record describes an object whose keys follow a known set and whose values share a type. It is useful for labels, feature configuration, status metadata, and handler maps.
type Role = "admin" | "editor" | "viewer";
type RoleLabel = Record<Role, string>;
const roleLabels: RoleLabel = {
admin: "Administrator",
editor: "Editor",
viewer: "Viewer"
};
With a union of literal keys, TypeScript can require each key. If the keys are dynamic strings, use Record<string, Value> deliberately because it permits any string key and may provide less protection.
Events and function results
Use ReturnType when a type should stay synchronized with a function implementation. Add Awaited when the function returns a promise.
async function fetchSettings() {
return {
theme: "dark" as const,
notifications: true
};
}
type Settings = Awaited<ReturnType<typeof fetchSettings>>;
type EventHandler<Event> = (event: Event) => void;
type ChangeHandler = EventHandler<{ value: string }>;
This approach avoids manually repeating the shape of a function's result. It is especially useful when a service function changes during refactoring.
Unions and custom mapped types
Extract and Exclude operate on union members. They are useful for narrowing event names, statuses, permissions, and feature variants.
type Status = "draft" | "published" | "archived";
type VisibleStatus = Exclude<Status, "archived">;
type PublishedStatus = Extract<Status, "published" | "archived">;
When the built-in utilities do not express the transformation, use a mapped type:
type OptionalExcept<T, K extends keyof T> =
Partial<T> & Pick<T, K>;
type Profile = {
id: string;
name: string;
bio: string;
};
type ProfileUpdate = OptionalExcept<Profile, "id">;
Mapped types iterate over keys, so they can also change modifiers or property values:
type NullableProperties<T> = {
[K in keyof T]: T[K] | null;
};
What to double-check
- Optional is not the same as nullable.
name?: stringmeans the property may be absent.name: string | nullmeans the property is present but can containnull. Check the API contract before choosingPartialor a nullable mapped type. - Check compiler settings. With
strictNullChecks, nullability is checked more precisely. WithexactOptionalPropertyTypes, an optional property does not automatically mean that explicitly assigningundefinedis valid. Treat these options as part of the type contract. - Remember that utility types are shallow.
Partial<User>makes User's direct properties optional; it does not recursively make nested objects optional. A recursive transformation requires a custom type and should be used carefully. - Inspect unions before transforming them. Conditional and mapped types can distribute over unions, producing a result different from the one you expected. Test a small example in an editor when a type becomes unexpectedly broad or narrow.
- Separate compile-time types from runtime validation. Utility types do not validate JSON, form input, or HTTP responses. Parse or validate untrusted data at runtime, then expose the validated result through a TypeScript type.
- Confirm readonly behavior at the boundary.
Readonly<T>prevents assignment through that type, but it does not make nested objects deeply immutable or freeze a JavaScript object at runtime.
Common mistakes
Using Partial for every update
A patch endpoint may accept optional fields, but a business operation may require a particular field. Prefer Pick plus Partial for the precise editable subset, or define a dedicated type when the rules are not a simple transformation.
Omitting fields that are actually client-controlled
Omit is not a security boundary. It describes what your TypeScript code intends to send; it does not prevent a caller from constructing arbitrary JSON. Enforce allowed fields on the server as well.
Assuming ReturnType unwraps promises
ReturnType<typeof fn> returns the declared result, which may be a Promise<T>. Use Awaited<ReturnType<typeof fn>> when you need the resolved value.
Fighting excess-property errors with broad index signatures
An object literal with an unexpected property can reveal a misspelled key or an incorrect model. Fix the shape first. Add an index signature only when arbitrary keys are genuinely part of the data contract.
Expecting a transformed type to alter runtime values
Types disappear during compilation. Making a property readonly, optional, or omitted from a derived type does not clone, remove, freeze, or validate the corresponding JavaScript value.
When to revisit
Return to this checklist whenever a data model, API contract, form, or compiler configuration changes. Review derived types after adding or renaming model properties, changing which fields the server generates, introducing a new React component variant, or converting a full update endpoint into a patch endpoint.
Also revisit utility-type choices when upgrading TypeScript. Built-in utilities, inference behavior, strictness options, and framework type definitions can evolve. Compile the project with the intended tsconfig, inspect the generated errors rather than relying on an isolated playground result, and add a small type test for any transformation that is important to an API boundary.
Before committing a new type transformation, use this practical sequence:
- Write down the runtime shape the code actually accepts or returns.
- Choose
Pick,Omit,Partial, or another utility based on that contract. - Check whether optional, nullable, and undefined values have different meanings.
- Test nested objects, unions, and excess properties explicitly.
- Keep runtime validation separate from compile-time convenience.
- Prefer a named custom type when a composed utility becomes difficult to read.
The best TypeScript utility type is not the shortest expression. It is the transformation that makes the allowed data obvious to the next developer and remains accurate when the underlying model changes.