TypeScript provides a powerful set of built-in utility types that help you transform existing types without rewriting them. These utilities make your code more flexible, readable, and safer.
This guide explains the most commonly used ones with very simple examples.
1. Object Shape Utilities
These utilities help modify the structure of object types.
Partial
Makes all properties optional.
1type User = { name: string; age: number }
2type PartialUser = Partial<User>
3
4// PartialUser -> { name?: string; age?: number }Required
Makes all properties required, even if they were originally optional.
1type User = { name?: string; age?: number }
2type StrictUser = Required<User>
3
4// StrictUser -> { name: string; age: number }Readonly
Makes all properties read-only and prevents reassignment.
1type User = { name: string; age: number }
2type ImmutableUser = Readonly<User>Pick
Creates a new type by selecting specific properties from an existing one.
1type User = { name: string; age: number; email: string }
2type UserPreview = Pick<User, 'name' | 'email'>Omit
Creates a new type by removing specific properties.
1type User = { name: string; age: number; password: string }
2type PublicUser = Omit<User, 'password'>Record
Creates a type with a set of keys and a defined type for values.
1type Roles = 'admin' | 'user'
2type RolePermissions = Record<Roles, number>
3// { admin: number; user: number }2. Union Modification Utilities
These utilities help work with union types.
Exclude
Removes one or more types from a union.
1type Status = 'loading' | 'success' | 'error'
2type WithoutLoading = Exclude<Status, 'loading'>Extract
Keeps only the matching types from a union.
1type Status = 'loading' | 'success' | 'error'
2type OnlySuccess = Extract<Status, 'success'>NotNullable
Removes null and undefined from a type.
1type Value = string | null | undefined
2type CleanValue = NotNullable<Value>
3// string
43. Function and Constructor Utilities
These types extract information related to functions.
ReturnType
Gets the return type of a function.
1function getAge() {
2 return 25
3}
4
5type Age = ReturnType<typeof getAge>
6// numberParameters
Gives a tuple of all parameter types of a function.
1function createUser(name: string, age: number) {}
2type UserArgs = Parameters<typeof createUser>
3// [string, number]ConstructorParameters
Extracts parameter types of a class constructor.
1class Person {
2 constructor(name: string, age: number) {}
3}
4
5type PersonArgs = ConstructorParameters<typeof Person>
6// [string, number]4. Async-Related Utility
Awaited
Extracts the resolved type of a promise.
1type ApiResponse = Promise<string>
2type Result = Awaited<ApiResponse>
3// stringWorks for nested promises as well:
1type Nested = Promise<Promise<number>>
2type Output = Awaited<Nested>
3// number5. String Manipulation Types
These are compile-time helpers for transforming string literal types.
Uppercase, Lowercase, Capitalize, Uncapitalize
type Name = "fayaz"
1type A = Uppercase<Name> // "FAYAZ"
2type B = Lowercase<Name> // "fayaz"
3type C = Capitalize<Name> // "Fayaz"
4type D = Uncapitalize<"Hello"> // "hello"These are useful when building API response keys, CSS variable names, or template literal types.
Final Thoughts
TypeScript’s utility types save time by allowing you to transform types instead of writing new ones from scratch. Once you start using them regularly, your codebase becomes cleaner, safer, and more expressive.