TypeScriptIntermediate

TypeScript Utility Types – Complete & Easy Cheatsheet

TypeScript utility types help you transform existing types into new ones without rewriting everything. They’re built-in, globally available, and extremely useful for real-world apps.

3 min read
Typesciprt Features

πŸ”„ Awaited<Type> (TS 4.5+)

Unwraps Promise types recursively (like await)

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

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

type C = Awaited<boolean | Promise<number>>;
// boolean | number

πŸ“Œ Use when working with async functions or .then() chains.

🧩 Partial<Type>

Makes all properties optional

interface Todo {
  title: string;
  description: string;
}

const update = (todo: Todo, data: Partial<Todo>) => ({
  ...todo,
  ...data
});

πŸ“Œ Perfect for update APIs & forms.

πŸ”’ Required<Type>

Makes all properties required

interface Props {
  a?: number;
  b?: string;
}

const obj: Required<Props> = {
  a: 1,
  b: "hi"
};

πŸ“Œ Opposite of Partial

🧊 Readonly<Type>

Prevents reassignment of properties

interface Todo {
  title: string;
}

const todo: Readonly<Todo> = {
  title: "Delete users"
};

// ❌ Error
todo.title = "Edit users";

πŸ“Œ Great for immutable data & Object.freeze.

πŸ—‚ Record<Keys, Type>

Creates object types with fixed keys

type Role = "admin" | "user";

const permissions: Record<Role, boolean> = {
  admin: true,
  user: false
};

πŸ“Œ Ideal for maps, configs, and lookup tables.

βœ‚οΈ Pick<Type, Keys>

Select specific properties

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

type UserPreview = Pick<User, "id" | "name">;

πŸ“Œ Useful for DTOs & lightweight responses.

πŸ—‘ Omit<Type, Keys>

Remove specific properties

type UserSafe = Omit<User, "email">;

πŸ“Œ Perfect for hiding sensitive fields.

🚫 Exclude<Union, Members>

Removes types from a union

type Status = "success" | "error" | "loading";

type Active = Exclude<Status, "loading">;
// "success" | "error"

🎯 Extract<Type, Union>

Keeps only matching union members

type Shape =
  | { kind: "circle"; r: number }
  | { kind: "square"; x: number };

type Circle = Extract<Shape, { kind: "circle" }>;

🚿 NonNullable<Type>

Removes null & undefined

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

πŸ“Œ Safe values only.

πŸ“₯ Parameters<Type>

Extracts function parameter types

type Fn = (id: number, name: string) => void;

type Args = Parameters<Fn>;
// [number, string]

πŸ— ConstructorParameters<Type>

Gets constructor arguments

class User {
  constructor(id: number, name: string) {}
}

type Args = ConstructorParameters<typeof User>;
// [number, string]

πŸ“€ ReturnType<Type>

Extracts return type of a function

const getUser = () => ({ id: 1, name: "Hardik" });

type User = ReturnType<typeof getUser>;

🧍 InstanceType<Type>

Gets instance type of a class

class Car {
  drive() {}
}

type CarInstance = InstanceType<typeof Car>;

πŸ›‘ NoInfer<Type> (TS 5.4+)

Prevents unwanted inference

function setTheme<T extends string>(
  themes: T[],
  active: NoInfer<T>
) {}

setTheme(["dark", "light"], "dark"); // βœ…
setTheme(["dark", "light"], "blue"); // ❌

🧠 ThisParameterType<Type>

Extracts this type from a function

function hex(this: Number) {
  return this.toString(16);
}

type ThisType = ThisParameterType<typeof hex>;
// Number

βœ‚οΈ OmitThisParameter<Type>

Removes this from function type

const fn = hex.bind(10);
// type-safe function without `this`

🧩 ThisType<Type>

Controls this inside object literals

type Obj<D, M> = {
  data: D;
  methods: M & ThisType<D & M>;
};

πŸ“Œ Used in advanced object factories.

πŸ”  String Utility Types

Uppercase<T>
type A = Uppercase<"hello">;
// "HELLO"
Lowercase<T>
type B = Lowercase<"HELLO">;
// "hello"
Capitalize<T>
type C = Capitalize<"hello world">;
// "Hello world"
Uncapitalize<T>
type D = Uncapitalize<"Hello">;
// "hello"

🧬 Template Literal Types

Create dynamic string types

type Event<T extends string> = `${T}Changed`;

type UserEvents = Event<"name" | "age">;
// "nameChanged" | "ageChanged"

πŸ“Œ Great for event systems & APIs.

⭐ Pro Tip

Most of these utilities are built using conditional types β€” mastering them unlocks next-level TypeScript.

thehardik | thehardik