Utility Types
Utility types are generic types shipped with TypeScript that transform other types. They live in the compiler's standard library and are erased at compile time.
Detailed Explanation
Most programs need the same type transformations: make every property optional, pick a subset of keys, unwrap a Promise, take a function's return type. TypeScript ships those transformations so you do not re-implement them in every project.
They fall into a few families.
Object shaping: Partial, Required, Readonly, Pick, Omit, Record. These are mapped types. They are covered on their own page because they show up in almost every codebase.
Union filtering: Exclude<T, U> removes from T anything assignable to U. Extract<T, U> keeps only those members. NonNullable<T> is Exclude<T, null | undefined>. These are distributive conditional types.
Function pieces: Parameters<T> is the argument tuple. ReturnType<T> is the return type. ConstructorParameters<T> and InstanceType<T> do the same for construct signatures. ThisParameterType and OmitThisParameter handle explicit this.
Promise and async: Awaited<T> recursively unwraps Promise (and thenables). It is what you want when a function returns Promise<Promise<T>> from a slip, or when you type await without calling await.
String manipulation: Uppercase, Lowercase, Capitalize, Uncapitalize. They operate on string literal types and are used with template literal types.
Misc: NoInfer<T> blocks a site from being used as an inference source. ThisType<T> is a hint for object-literal this in options bags. Uppercase and friends have no runtime.
Two rules keep utilities useful. First, they transform types, not values. Partial<User> does not make a partial object. You still build the object in JavaScript; the utility describes it. Second, they compose. Partial<Pick<User, "email" | "name">> is a normal type. Prefer a named alias at a public boundary so error messages stay short.
Do not reach for a utility when a simpler type is clearer. Pick<User, "id"> is fine; Pick<User, keyof User> is just User. Record<string, unknown> is often better written as a specific interface once you know the keys. And do not import a utility from a package if it is already in lib — Partial and ReturnType are global types, not tslib values.
When a built-in utility almost fits, copy its definition from the TypeScript lib .d.ts and adjust it. That is how they are meant to be learned: they are ordinary mapped and conditional types with well-known names.
Code Examples
1. Function pieces.
// 1. Function pieces.
function charge(cents: number, currency: string): boolean {
return cents > 0;
}
type ChargeArgs = Parameters<typeof charge>; // [cents: number, currency: string]
type ChargeRet = ReturnType<typeof charge>; // boolean2. Union filters and Awaited.
// 2. Union filters and Awaited.
type Status = "idle" | "loading" | "error" | null;
type Known = NonNullable<Status>; // "idle" | "loading" | "error"
type Failures = Extract<Known, "error">; // "error"
type Active = Exclude<Known, "error">; // "idle" | "loading"
type Nested = Awaited<Promise<Promise<string>>>; // string3. String utilities plus Record.
// 3. String utilities plus Record.
type Event = "click" | "focus";
type HandlerName = `on${Capitalize<Event>}`; // "onClick" | "onFocus"
type Handlers = Record<HandlerName, () => void>;
const handlers: Handlers = {
onClick: () => {},
onFocus: () => {},
};Common Gotchas
`ReturnType<typeof fn>` needs a concrete function type
on an overloaded function it resolves to the *last* overload, which is often the most general one. Prefer an explicit alias if overloads matter.
`Parameters` and `ReturnType` require a function type
passing a class or a non-callable value is a type error. Use `typeof fn`, not an instance.
Utilities are global in the TS lib, not imported
you do not `import { Partial } from "typescript"`. If a name is missing, your `lib` or TypeScript version is too old.
Composing many utilities inline produces unreadable errors
alias the result. `type UserDraft = Partial<Pick<User, "email" | "name">>` prints as `UserDraft` in some diagnostics and as the expansion in others.