Utility types are built-in generic types that transform other types, like making all properties optional or selecting specific properties.
TypeScript provides several built-in utility types that help transform and manipulate existing types. These are implemented using mapped types and conditional types under the hood.
Partial<T> makes all properties of T optional. Useful when you want to update only some properties of an object: function updateUser(user: Partial<User>) { ... }
Required<T> is the opposite—it makes all properties required, removing any optional modifiers.
Pick<T, K> creates a type with only the specified properties: type UserPreview = Pick<User, 'id' | 'name'>
Omit<T, K> creates a type without the specified properties: type UserWithoutPassword = Omit<User, 'password'>
Record<K, V> creates an object type with keys of type K and values of type V: Record<string, number> is { [key: string]: number }
ReturnType<T> extracts the return type of a function type. Parameters<T> extracts the parameter types as a tuple.
NonNullable<T> removes null and undefined from T. Exclude<T, U> removes types from a union. Extract<T, U> extracts types from a union.
These utility types compose well together and are essential for writing DRY, maintainable TypeScript code.
Utility types are built-in generic types that transform other types, like making all properties optional or selecting specific properties.
Join our network of elite AI-native engineers.