TypeScript Utility Types Cheatsheet
typescriptAll TypeScript built-in utility types with examples.
Object Property Modifiers
Partial<Type>Makes all properties of Type optional
// Before: { name: string; age: number }
type Result = Partial<User>;
// After: { name?: string; age?: number }Required<Type>Makes all properties of Type required
// Before: { name?: string; age?: number }
type Result = Required<User>;
// After: { name: string; age: number }Readonly<Type>Makes all properties of Type readonly
// Before: { name: string; age: number }
type Result = Readonly<User>;
// After: { readonly name: string; readonly age: number }Object Property Selection
Pick<Type, Keys>Creates a type with only the specified keys from Type
// Before: { name: string; age: number; email: string }
type Result = Pick<User, 'name' | 'email'>;
// After: { name: string; email: string }Omit<Type, Keys>Creates a type with all properties except the specified keys
// Before: { name: string; age: number; email: string }
type Result = Omit<User, 'age'>;
// After: { name: string; email: string }Record<Keys, Type>Creates an object type with keys of type Keys and values of type Type
// Before: manually defining { [key: string]: User }
type Result = Record<string, User>;
// After: { [x: string]: User }Union Type Manipulation
Exclude<UnionType, ExcludedMembers>Removes types from a union that are assignable to ExcludedMembers
// Before: 'a' | 'b' | 'c'
type Result = Exclude<'a' | 'b' | 'c', 'a'>;
// After: 'b' | 'c'Extract<Type, Union>Extracts types from a union that are assignable to Union
// Before: 'a' | 'b' | 'c'
type Result = Extract<'a' | 'b' | 'c', 'a' | 'f'>;
// After: 'a'NonNullable<Type>Removes null and undefined from Type
// Before: string | null | undefined
type Result = NonNullable<string | null | undefined>;
// After: stringFunction Type Extraction
Parameters<Type>Extracts parameter types from a function type as a tuple
// Before: (a: string, b: number) => void
type Result = Parameters<typeof fn>;
// After: [a: string, b: number]ReturnType<Type>Extracts the return type of a function type
// Before: () => { name: string; age: number }
type Result = ReturnType<typeof getUser>;
// After: { name: string; age: number }ConstructorParameters<Type>Extracts parameter types from a constructor function as a tuple
// Before: class User { constructor(name: string, age: number) {} }
type Result = ConstructorParameters<typeof User>;
// After: [name: string, age: number]InstanceType<Type>Extracts the instance type of a constructor function
// Before: class User { name: string; }
type Result = InstanceType<typeof User>;
// After: UserThis Parameter Types
ThisParameterType<Type>Extracts the type of the this parameter from a function type
// Before: function fn(this: User, x: number) {}
type Result = ThisParameterType<typeof fn>;
// After: UserOmitThisParameter<Type>Removes the this parameter from a function type
// Before: (this: User, x: number) => void
type Result = OmitThisParameter<typeof fn>;
// After: (x: number) => voidThisType<Type>Marker for contextual this type (no transformation, used with noImplicitThis)
const obj: ThisType<{ name: string }> & { greet(): void } = {
greet() { console.log(this.name); }
};String Manipulation Types
Uppercase<StringType>Converts string literal type to uppercase
// Before: 'hello'
type Result = Uppercase<'hello'>;
// After: 'HELLO'Lowercase<StringType>Converts string literal type to lowercase
// Before: 'HELLO'
type Result = Lowercase<'HELLO'>;
// After: 'hello'Capitalize<StringType>Converts first character of string literal type to uppercase
// Before: 'hello'
type Result = Capitalize<'hello'>;
// After: 'Hello'Uncapitalize<StringType>Converts first character of string literal type to lowercase
// Before: 'Hello'
type Result = Uncapitalize<'Hello'>;
// After: 'hello'Promise and Async Types
Awaited<Type>Recursively unwraps Promise types to get the resolved value type
// Before: Promise<Promise<string>>
type Result = Awaited<Promise<Promise<string>>>;
// After: stringAwaited<ReturnType<typeof asyncFn>>Get the resolved type of an async functions return value
async function fetchUser() { return { name: 'John' }; }
type Result = Awaited<ReturnType<typeof fetchUser>>;
// { name: string }Awaited<Type | Promise<Type>>Handles union types with mixed Promise and non-Promise types
// Before: string | Promise<number>
type Result = Awaited<string | Promise<number>>;
// After: string | numberCommon Utility Patterns
type DeepPartial<T> = { [P in keyof T]?: DeepPartial<T[P]> }Custom utility making all nested properties optional recursively
type Nested = { user: { name: string; addr: { city: string } } };
type Result = DeepPartial<Nested>;
// All levels become optionalPartial<Pick<Type, Keys>>Make only specific properties optional
type User = { name: string; age: number; email: string };
type Result = Partial<Pick<User, 'age' | 'email'>>;
// { age?: number; email?: string }Required<Omit<Type, Keys>>Make all properties required except excluded ones
type User = { name?: string; age?: number; id: string };
type Result = Required<Omit<User, 'id'>>;
// { name: string; age: number }Record<'key1' | 'key2', Type>Create object with specific literal keys
type Status = 'pending' | 'done' | 'error';
type StatusMap = Record<Status, { label: string }>;
// { pending: {...}; done: {...}; error: {...} }Extract<keyof Type, string>Get only string keys from an object type
type Obj = { 0: 'a'; name: 'b'; [Symbol.iterator]: 'c' };
type Result = Extract<keyof Obj, string>;
// 'name'NonNullable<Type[number]>Get non-nullable element type from an array that may contain nulls
type Arr = (string | null | undefined)[];
type Result = NonNullable<Arr[number]>;
// string