Skip to content

TypeScript utility types: Partial, Omit, Exclude

Utility types are generic types that ship with TypeScript in its standard library (lib.es5.d.ts), available everywhere without an import. Each one transforms a type you already have: Partial<Order> is an order with every field optional, Omit<Order, "id"> is an order without its ID, ReturnType<typeof loadOrder> is whatever loadOrder returns. Using them keeps derived types in sync with their source: when Order gains a field, every Partial<Order> gains it too.

This hub covers the utility types you will use most, grouped by what they act on: object properties, union members, and function and class types. Each section shows the actual definition from the TypeScript 7.0 library, because once you can read the definition, you can predict the edge cases. The definitions use mapped and conditional types, which you do not need to understand to use them.

All samples are complete ES modules from an invented online shop, OrdersPortal, compiled with TypeScript 7.0.2 (tsc --strict --target es2025 --module nodenext) and run with Node.js 22. Save one as sample.ts next to a package.json containing {"type": "module"}, then run npx tsc --strict sample.ts and node sample.js. Compiler errors are quoted as tsc prints them, without the file and line prefix.

Topic Since What it does
Partial TypeScript 2.1 Makes every property optional.
Required TypeScript 2.8 Makes every property required.
Pick and Omit Pick 2.1; Omit 3.5 Keeps or removes named properties.
Readonly and Record TypeScript 2.1 Makes properties read-only; builds an object type from keys and a value type.
Exclude and Extract TypeScript 2.8 Removes or keeps members of a union.
NonNullable TypeScript 2.8 Removes null and undefined from a type.
Function and constructor types 2.8 to 4.5 Reads parameter, return, constructor and instance types.

Partial<T> arrived in TypeScript 2.1. It makes every property of T optional, which fits update (“patch”) operations, where the caller sends only the fields that change, and options objects merged over defaults.

// Definition in lib.es5.d.ts
type Partial<T> = { [P in keyof T]?: T[P] };

Partial is shallow: nested objects keep their required fields. It is also very permissive: {} is a valid Partial<Order>, so a function that accepts one should decide what an empty patch means. For the “options over defaults” pattern, spreading { ...defaults, ...options } produces the full type again.

interface Order {
id: string;
status: "pending" | "paid" | "shipped";
total: number;
note?: string;
}
function updateOrder(order: Order, patch: Partial<Omit<Order, "id">>): Order {
return { ...order, ...patch };
}
interface ExportOptions {
format: "csv" | "json";
includeNotes: boolean;
delimiter: string;
}
const defaultExport: ExportOptions = { format: "csv", includeNotes: false, delimiter: "," };
function exportOptions(options: Partial<ExportOptions> = {}): ExportOptions {
return { ...defaultExport, ...options };
}
const order: Order = { id: "ORD-1", status: "pending", total: 40 };
console.log(updateOrder(order, { status: "paid", note: "gift" }));
console.log(exportOptions({ format: "json" }));

Output:

{ id: 'ORD-1', status: 'paid', total: 40, note: 'gift' }
{ format: 'json', includeNotes: false, delimiter: ',' }

Pitfalls:

  • undefined can overwrite. Unless exactOptionalPropertyTypes is on, { status: undefined } is a valid Partial<Order>, and spreading it erases the status. Filter out undefined values or enable that option.
  • Omit the identity. Partial<Order> would let a patch change id; combine it with Omit as in the sample.

Required<T> arrived in TypeScript 2.8. It is the opposite of Partial: it removes the ? from every property, so all of them must be present. The usual use is a value that started with optional fields and has since been fully resolved, such as configuration after defaults have been applied.

// Definition in lib.es5.d.ts: -? removes optionality
type Required<T> = { [P in keyof T]-?: T[P] };
interface ShippingConfig {
carrier?: string;
maxWeightKg?: number;
insured?: boolean;
}
type ResolvedShippingConfig = Required<ShippingConfig>;
function resolveShipping(config: ShippingConfig): ResolvedShippingConfig {
return {
carrier: config.carrier ?? "ParcelCo",
maxWeightKg: config.maxWeightKg ?? 20,
insured: config.insured ?? false,
};
}
const resolved = resolveShipping({ insured: true });
// No undefined checks needed: every property is required now.
console.log(`${resolved.carrier}, up to ${resolved.maxWeightKg.toFixed(1)} kg, insured=${resolved.insured}`);

Output:

ParcelCo, up to 20.0 kg, insured=true

Leaving out insured in resolveShipping fails with error TS2741: Property 'insured' is missing in type '{ carrier: string; maxWeightKg: number; }' but required in type 'Required<ShippingConfig>'.

Pitfalls:

  • -? does not remove explicit undefined. For insured: boolean | undefined (no ?), Required keeps the undefined; only the optional marker is removed.
  • Shallow, like Partial. Nested optional properties stay optional.

Pick<T, K> arrived in TypeScript 2.1 and Omit<T, K> in 3.5. Pick keeps only the listed properties; Omit keeps everything except the listed properties. They create the many “views” of one entity that an application needs: a summary row for a list, a creation payload without server-generated fields, a public profile without internal ones.

// Definitions in lib.es5.d.ts
type Pick<T, K extends keyof T> = { [P in K]: T[P] };
type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;

Note the difference in the constraints: Pick requires keys that exist on T, so a typo is an error, but Omit accepts any key, so Omit<Order, "totl"> silently omits nothing.

interface Order {
id: string;
customerId: string;
status: "pending" | "paid" | "shipped";
total: number;
createdAt: string;
internalNotes: string;
}
type OrderSummary = Pick<Order, "id" | "status" | "total">;
type NewOrder = Omit<Order, "id" | "createdAt" | "internalNotes">;
let nextId = 1043;
function createOrder(input: NewOrder): Order {
return { ...input, id: `ORD-${nextId++}`, createdAt: "2026-11-18", internalNotes: "" };
}
function toSummary({ id, status, total }: Order): OrderSummary {
return { id, status, total };
}
const created = createOrder({ customerId: "C-1", status: "pending", total: 59.9 });
console.log(toSummary(created));

Output:

{ id: 'ORD-1043', status: 'pending', total: 59.9 }

Pick<Order, "totl"> fails with error TS2344: Type '"totl"' does not satisfy the constraint 'keyof Order'., while Omit<Order, "totl"> compiles.

Pitfalls:

  • Omit does not check keys. Write a strict variant if typos matter: type StrictOmit<T, K extends keyof T> = Omit<T, K>;.
  • Omit on a union flattens it. Omit<A | B, "x"> uses keyof (A | B), the keys common to both, and loses the union. Map over the union with a distributive helper (T extends unknown ? Omit<T, K> : never) when you need to keep it.

Readonly<T> and Record<K, T> arrived in TypeScript 2.1. Readonly<T> marks every property readonly, a good fit for values that must not be changed after creation, such as state passed to a UI component. ReadonlyArray<T> (readonly T[]) does the same for arrays by removing push, splice and other mutating methods.

Record<K, T> builds an object type whose keys are K and whose values are T. With a union of literal keys, it requires every key, which makes it ideal for lookup tables that must stay complete: add a status to the union and every Record<OrderStatus, ...> table fails to compile until the new entry is added. With string as K, it is an index signature.

// Definitions in lib.es5.d.ts
type Readonly<T> = { readonly [P in keyof T]: T[P] };
type Record<K extends keyof any, T> = { [P in K]: T };
type OrderStatus = "pending" | "paid" | "shipped" | "cancelled";
const statusLabels: Record<OrderStatus, string> = {
pending: "Awaiting payment",
paid: "Paid",
shipped: "On its way",
cancelled: "Cancelled",
};
interface OrderView {
id: string;
status: OrderStatus;
lines: readonly string[];
}
function render(view: Readonly<OrderView>): string {
// view.status = "paid"; would be error TS2540 (read-only property)
return `${view.id}: ${statusLabels[view.status]} (${view.lines.length} lines)`;
}
const counts: Record<string, number> = {};
for (const s of ["paid", "paid", "pending"] as const) counts[s] = (counts[s] ?? 0) + 1;
console.log(render({ id: "ORD-1", status: "shipped", lines: ["SKU-RED-01"] }));
console.log(counts);

Output:

ORD-1: On its way (1 lines)
{ paid: 2, pending: 1 }

Removing the cancelled entry from statusLabels fails with error TS2741: Property 'cancelled' is missing in type '{ pending: string; paid: string; shipped: string; }' but required in type 'Record<OrderStatus, string>'.

Pitfalls:

  • Readonly is shallow and compile-time only. view.lines above needed its own readonly; use Object.freeze when run-time immutability matters.
  • Record<string, T> claims every key exists. Reads return T, not T | undefined, unless noUncheckedIndexedAccess is on.

Exclude<T, U> and Extract<T, U> arrived in TypeScript 2.8. Both work on union types: Exclude removes the members of T that are assignable to U, and Extract keeps only those members. Use them to derive a narrower union from a wider one instead of repeating the members.

They are distributive conditional types, so they test each member of T separately. That also makes Extract useful on discriminated unions: Extract<Payment, { kind: "card" }> selects the card variant by its tag. Do not confuse them with Omit and Pick, which act on the properties of an object type.

// Definitions in lib.es5.d.ts
type Exclude<T, U> = T extends U ? never : T;
type Extract<T, U> = T extends U ? T : never;
type OrderStatus = "pending" | "paid" | "shipped" | "delivered" | "cancelled";
type OpenStatus = Exclude<OrderStatus, "delivered" | "cancelled">; // "pending" | "paid" | "shipped"
type FinalStatus = Extract<OrderStatus, "delivered" | "cancelled">;
type Payment =
| { kind: "card"; last4: string; amount: number }
| { kind: "invoice"; dueDays: number; amount: number }
| { kind: "voucher"; code: string };
type CardPayment = Extract<Payment, { kind: "card" }>;
type ChargeablePayment = Extract<Payment, { amount: number }>; // card | invoice
function isFinal(status: OrderStatus): status is FinalStatus {
return status === "delivered" || status === "cancelled";
}
function chargeTotal(payments: ChargeablePayment[]): number {
return payments.reduce((sum, p) => sum + p.amount, 0);
}
const open: OpenStatus[] = ["pending", "paid"];
const card: CardPayment = { kind: "card", last4: "4242", amount: 40 };
console.log(open, isFinal("cancelled"), chargeTotal([card, { kind: "invoice", dueDays: 30, amount: 15 }]));

Output:

[ 'pending', 'paid' ] true 55

Assigning "delivered" to an OpenStatus fails with error TS2322: Type '"delivered"' is not assignable to type 'OpenStatus'.

Pitfalls:

  • Typos produce no error. Exclude<OrderStatus, "canceled"> removes nothing and compiles. Constrain a helper (type Without<T, U extends T> = Exclude<T, U>) when the removed members must exist.
  • They do nothing useful on object types. Exclude<Order, "id"> is just Order; you wanted Omit.

NonNullable<T> arrived in TypeScript 2.8. It removes null and undefined from a type: NonNullable<string | null | undefined> is string. Since TypeScript 4.8 it is defined as an intersection with the empty object type, {}, which matches every value except null and undefined.

// Definition in lib.es5.d.ts (since TypeScript 4.8)
type NonNullable<T> = T & {};

Use it for the type of a value after a null check, in particular in generic helpers that filter or assert: a compact function that drops missing entries, or an assertion that a lookup succeeded. The compiler does this narrowing automatically for ordinary if checks; NonNullable is how you write the resulting type in a signature.

interface Order {
id: string;
couponCode: string | null;
shippedAt?: string;
}
function compact<T>(items: readonly T[]): NonNullable<T>[] {
return items.filter((item): item is NonNullable<T> => item !== null && item !== undefined);
}
function required<T>(value: T, message: string): NonNullable<T> {
if (value === null || value === undefined) throw new Error(message);
return value;
}
const orders: Order[] = [
{ id: "ORD-1", couponCode: "WELCOME10", shippedAt: "2026-11-02" },
{ id: "ORD-2", couponCode: null },
];
const coupons: string[] = compact(orders.map((o) => o.couponCode));
const shipped: string[] = compact(orders.map((o) => o.shippedAt));
console.log(coupons, shipped);
try {
required(orders[1].shippedAt, `${orders[1].id} has not shipped`);
} catch (error) {
console.log(error instanceof Error ? error.message : error);
}

Output:

[ 'WELCOME10' ] [ '2026-11-02' ]
ORD-2 has not shipped

Pitfalls:

  • It does not touch nested properties. NonNullable<Order> is still an Order with a nullable couponCode. Combine it with a mapped type if you need that.
  • Prefer narrowing in ordinary code. An if (x != null) check needs no utility type; reach for NonNullable in generic signatures.

These utility types read the types out of a function or class type, usually with typeof applied to an existing function or class. ReturnType and InstanceType arrived in TypeScript 2.8, Parameters and ConstructorParameters in 3.1, and Awaited in 4.5.

  • Parameters<F> is a tuple of a function’s parameter types; ReturnType<F> is its return type.
  • ConstructorParameters<C> is a tuple of a class constructor’s parameter types; InstanceType<C> is the type of the instance it creates. Since TypeScript 4.3 both also accept abstract classes.
  • Awaited<T> unwraps promises recursively, as await does; Awaited<ReturnType<F>> is what an async function resolves to.

They let wrappers, factories and test helpers follow the signature of the code they wrap, without repeating it.

// Definitions in lib.es5.d.ts
type Parameters<T extends (...args: any) => any> = T extends (...args: infer P) => any ? P : never;
type ConstructorParameters<T extends abstract new (...args: any) => any> =
T extends abstract new (...args: infer P) => any ? P : never;
class OrderApiClient {
constructor(
public readonly baseUrl: string,
public readonly timeoutMs: number = 5000,
) {}
async getOrder(id: string, includeLines: boolean): Promise<{ id: string; lines: number }> {
return { id, lines: includeLines ? 2 : 0 };
}
}
type ClientArgs = ConstructorParameters<typeof OrderApiClient>; // [baseUrl: string, timeoutMs?: number]
type Client = InstanceType<typeof OrderApiClient>; // OrderApiClient
type GetOrderArgs = Parameters<Client["getOrder"]>; // [id: string, includeLines: boolean]
type GetOrderResult = Awaited<ReturnType<Client["getOrder"]>>; // { id: string; lines: number }
// A factory that always passes the right constructor arguments.
function createClient(...args: ClientArgs): Client {
return new OrderApiClient(...args);
}
// A wrapper that keeps the wrapped method's signature.
async function withLogging(client: Client, ...args: GetOrderArgs): Promise<GetOrderResult> {
console.log(`GET ${client.baseUrl}/orders/${args[0]} (timeout ${client.timeoutMs} ms)`);
return client.getOrder(...args);
}
const client = createClient("https://api.example.test");
const result = await withLogging(client, "ORD-1042", true);
console.log(result);

Output:

GET https://api.example.test/orders/ORD-1042 (timeout 5000 ms)
{ id: 'ORD-1042', lines: 2 }

Calling createClient(5000) fails with error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.

Pitfalls:

  • Overloaded functions give the last overload. ReturnType and Parameters see only the last overload signature, which is often the most general one.
  • Use typeof for values. ReturnType<loadOrder> is an error, because loadOrder is a value; write ReturnType<typeof loadOrder>.
You want to Use
Accept only some fields of an object, such as a patch Partial<T>, often with Omit for fields that must not change
Express that defaults have been filled in Required<T>
Build a smaller view of an object Pick<T, K>, or Omit<T, K> when removing fewer fields
Protect a value from changes in the type system Readonly<T>, readonly T[]
A complete lookup table for a set of keys Record<KeyUnion, Value>
Narrow a union of literals or variants Exclude<T, U>, Extract<T, U>
Describe a value after removing null NonNullable<T>
Follow another function’s or class’s signature Parameters, ReturnType, ConstructorParameters, InstanceType, Awaited

Other built-ins worth knowing: NoInfer<T> (TypeScript 5.4) blocks inference from one parameter, ThisParameterType and OmitThisParameter read this types (see Classes and decorators), and Uppercase, Lowercase, Capitalize and Uncapitalize transform string literal types (see Template literal types).

What is the difference between Omit and Exclude? Omit<T, K> removes properties from an object type. Exclude<T, U> removes members from a union type. Omit is implemented with Exclude on keyof T: Pick<T, Exclude<keyof T, K>>.

Why does Omit<Order, "totl"> compile when Pick<Order, "totl"> does not? Pick constrains its keys to keyof T; Omit accepts keyof any, any string, number or symbol. A typo in Omit therefore removes nothing. Teams that care define a StrictOmit<T, K extends keyof T>.

How would you type a “patch” endpoint for an order where the ID cannot change? Partial<Omit<Order, "id">>: all fields optional, with id removed. Consider exactOptionalPropertyTypes so an explicit undefined cannot erase a field, and validate at run time that the patch is not empty if that matters.

Why is Record<OrderStatus, string> better than { [status: string]: string } for a label table? With a union of literal keys, Record requires an entry for every status and rejects unknown keys, so adding a status produces a compile error until its label exists. The index signature accepts any key and never reports a missing one.

What does ReturnType give you for an overloaded function? The return type of the last overload signature, because conditional type inference against an overloaded function uses the last signature. If you need another overload’s type, declare it separately.

Senior scenario: OrdersPortal has Order, OrderDto, CreateOrderRequest, UpdateOrderRequest and OrderListItem, all written by hand, and they keep drifting. How would you restructure them? Keep one source type, ideally generated from the API contract or database schema, and derive the rest: CreateOrderRequest = Omit<Order, "id" | "createdAt">, UpdateOrderRequest = Partial<CreateOrderRequest>, OrderListItem = Pick<Order, "id" | "status" | "total">. Where a view genuinely differs (renamed or computed fields), write that type explicitly and add a mapping function with tests. Keep derived names so error messages stay readable, and use a strict Omit variant so a renamed field breaks the build instead of silently leaking.