Back to Cheat Sheets
Cheat Sheets/TypeScript Utilities Reference
typescript

TypeScript Utilities Reference

Built-in TypeScript utility types

TypeScriptTypesUtilities
Type Modifiers
Partial<T>
type Partial<T> = { [P in keyof T]?: T[P] }

All properties optional

Required<T>
type Required<T> = { [P in keyof T]-?: T[P] }

All properties required

Readonly<T>
type Readonly<T> = { readonly [P in keyof T]: T[P] }

All properties readonly

Pick<T, K>
type Pick<T, K> = { [P in K]: T[P] }

Select specific properties

Omit<T, K>
type Omit<T, K> = Pick<T, Exclude<keyof T, K>>

Remove specific properties

Record<K, T>
type Record<K, T> = { [P in K]: T }

Construct object type

Advanced Types
Exclude<T, U>
type Exclude<T, U> = T extends U ? never : T

Remove types from union

Extract<T, U>
type Extract<T, U> = T extends U ? T : never

Extract types from union

NonNullable<T>
type NonNullable<T> = T & {}

Remove null and undefined

ReturnType<F>
type R = ReturnType<typeof myFunc>

Get function return type

Parameters<F>
type P = Parameters<typeof myFunc>

Get function parameter types