What are utility types in TypeScript
· Category: TypeScript
Short answer
Utility types are built-in generic types that transform existing types into new variants, such as making properties optional or extracting subsets.
How it works
TypeScript ships with utilities including Partial<T> (all optional), Required<T> (all required), Readonly<T> (immutable), Pick<T, K> (select keys), Omit<T, K> (exclude keys), Record<K, T> (map keys to values), Exclude<T, U> (remove union members), Extract<T, U> (keep union members), NonNullable<T> (remove null/undefined), Parameters<T> (tuple of args), and ReturnType<T> (return type).
Example
interface User { id: number; name: string; email: string; }
type UserPreview = Pick<User, 'id' | 'name'>;
Why it matters
Utility types reduce duplication and let you derive types from a single source of truth. When the base interface changes, derived types update automatically.