Special Sponsor:PromptBuilder— Fast, consistent prompt creation powered by 1,000+ expert templates.
Make your Product visible here.Contact Us
Taking new clients

Need a dev team that ships?

011BQ builds TypeScript-first products, migrations, and internal tools for startups and scale-ups.

  • JS/TS migration & codebase modernisation
  • Custom dev tools & internal platforms
  • React, Next.js & Node.js engineering
  • Code review, architecture & tech advisory

Or reach us directly

011bq.com

Send us a message

We respond within 1 business day.

check_dark

Thank You!

Your message has been successfully sent. We will get back to you soon!

Message sent!

Thanks for reaching out. The 011BQ team will get back to you within 1 business day.

HomeChevronBlogChevronTypeScript Utility Types: The Complete Guide with Examples

TypeScript Utility Types: The Complete Guide with Examples

j
js2ts Team
22/05/2026·1 minute 51 seconds read
TypeScript Utility Types: The Complete Guide with ExamplesTypeScript Utility Types: The Complete Guide with Examples

What Are TypeScript Utility Types?

TypeScript ships with a set of built-in generic types that transform other types. These utility types let you derive new types from existing ones without code duplication. Mastering them dramatically reduces the need for manual type maintenance.

Object Modification Utilities

Partial<T> — Makes all properties optional:

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

type UserUpdate = Partial<User>;
// { id?: number; name?: string; email?: string; }

async function updateUser(id: number, data: Partial<User>) {
  await db.user.update({ where: { id }, data });
}

Required<T> — Makes all properties required (opposite of Partial):

type CompleteUser = Required<UserUpdate>;
// { id: number; name: string; email: string; }

Readonly<T> — Makes all properties read-only:

type ImmutableUser = Readonly<User>;
const user: ImmutableUser = { id: 1, name: 'Alice', email: 'a@example.com' };
user.name = 'Bob'; // Error: Cannot assign to 'name' because it is a read-only property.

Property Selection Utilities

Pick<T, K> — Keeps only the specified keys:

type UserPreview = Pick<User, 'id' | 'name'>;
// { id: number; name: string; }

// Useful for API responses that don't need all fields
async function getUserPreview(id: number): Promise<UserPreview> {
  return db.user.findUnique({ where: { id }, select: { id: true, name: true } });
}

Omit<T, K> — Removes the specified keys:

type CreateUserInput = Omit<User, 'id'>;
// { name: string; email: string; }

type PublicUser = Omit<User, 'email'>;
// { id: number; name: string; }

Record and Union Utilities

Record<K, V> — Creates an object type with keys K and values V:

type RolePermissions = Record<'admin' | 'user' | 'guest', string[]>;

const permissions: RolePermissions = {
  admin: ['read', 'write', 'delete'],
  user: ['read', 'write'],
  guest: ['read'],
};

Exclude<T, U> and Extract<T, U> — Filter union types:

type Status = 'pending' | 'active' | 'deleted';

type ActiveStatus = Exclude<Status, 'deleted'>;
// 'pending' | 'active'

type VisibleStatus = Extract<Status, 'pending' | 'active'>;
// 'pending' | 'active'

NonNullable<T> — Removes null and undefined:

type MaybeString = string | null | undefined;
type DefiniteString = NonNullable<MaybeString>; // string

Function Utilities

ReturnType<T> — Extracts the return type of a function:

async function getUser() {
  return { id: 1, name: 'Alice', email: 'a@example.com' };
}

type GetUserResult = Awaited<ReturnType<typeof getUser>>;
// { id: number; name: string; email: string; }

Parameters<T> — Extracts function parameter types as a tuple:

function createUser(name: string, email: string, role: 'admin' | 'user') {}

type CreateUserParams = Parameters<typeof createUser>;
// [name: string, email: string, role: 'admin' | 'user']

Awaited<T>

New in TypeScript 4.5, Awaited<T> recursively unwraps Promise types:

type A = Awaited<Promise<string>>; // string
type B = Awaited<Promise<Promise<number>>>; // number

For a deep dive into generics that power these utility types, see our TypeScript Generics guide.

Share