TypeScript Utility Types
Transform types with Partial, Pick, Omit, Record, and ReturnType
Overview
TypeScript ships built-in utility types that transform existing types. They reduce duplication and keep DTOs, form state, and API layers in sync with core interfaces.
Syntax / Usage
interface User {
id: string
name: string
email: string
role: 'admin' | 'user'
}
type PartialUser = Partial<User> // all optional
type RequiredUser = Required<PartialUser> // all required
type UserPreview = Pick<User, 'id' | 'name'>
type UserWithoutEmail = Omit<User, 'email'>
type ReadonlyUser = Readonly<User>
type RoleMap = Record<'admin' | 'user', string>
type CreateUser = Omit<User, 'id'>
type UpdateUser = Partial<CreateUser>
type GreetFn = (name: string) => string
type GreetReturn = ReturnType<GreetFn> // string
type GreetParams = Parameters<GreetFn> // [string]
Examples
Form state from entity:
type UserForm = Partial<Pick<User, 'name' | 'email'>> & {
password: string
}
Extract promise result:
type FetchUserResult = Awaited<ReturnType<typeof fetchUser>>
Non-nullable fields:
type NonNullableUser = {
[K in keyof User]: NonNullable<User[K]>
}
Common Mistakes
Partialeverywhere when only some fields should be optional—usePick+PartialOmitremoving fields still required downstream- Deep partial needs a custom mapped type—
Partialis shallow - Over-nesting utility types hurts readability—alias intermediate types
See Also
interfaces generics unions type-guards