Skip to content

TypeScript Utility Types Explained

TypeScript's built-in utility types and the keywords that travel with them, grouped by job: reshape an object, filter a union, describe a function, transform a literal string, and capture types from values. Each row shows the type and a real alias you would write.

Utility types are generic functions for types: they take one or two types and return a new one, so you do not have to spell every shape by hand. They shine for derived types, where the source of truth is another type or a value and you want your types to track it automatically. The rule of thumb is to derive rather than duplicate: if you change the source, the derived type follows.

Reference table · 22 entries
22 of 22 rows
Object shape
T with every property made optional.type Update = Partial<User>
T with every property made required.type Strict = Required<Opts>
T with every property made readonly.type Frozen = Readonly<User>
T with only the keys in K kept.type Preview = Pick<User, "id" | "name">
T with the keys in K removed.type SafeUser = Omit<User, "password">
An object whose keys are K and whose values are V.type Scores = Record<string, number>
Union filtering
The union U with members assignable to X removed.type NoNull = Exclude<T, null>
The members of U that are assignable to X.type OnlyStr = Extract<T, string>
T with null and undefined removed.type Def = NonNullable<T>
Function types
A tuple of the parameter types of function F.type P = Parameters<typeof fn>
The type that function F returns.type R = ReturnType<typeof fn>
A tuple of the parameter types of constructor F.type C = ConstructorParameters<typeof Date>
The instance type produced by constructor F.type D = InstanceType<typeof Date>
The type a Promise resolves to, recursively.type Data = Awaited<Promise<User>>
Literal string transforms
The string literal S in upper case.type A = Uppercase<"abc"> // "ABC"
The string literal S in lower case.type B = Lowercase<"ABC"> // "abc"
S with the first character in upper case.type C = Capitalize<"abc"> // "Abc"
S with the first character in lower case.type D = Uncapitalize<"Abc"> // "aBc"
Related keywords
A union of the property keys of object type T.type K = keyof User
The type of a value, without spelling it again.type Config = typeof defaults
Capture a type inside a conditional for reuse.type El<T> = T extends Array<infer I> ? I : never
Pick type X or Y based on whether T is assignable to U.type IsStr<T> = T extends string ? true : false