← devnestio

TypeScript Utility Types Reference

TypeScript ships 22 built-in utility types that transform existing types without re-declaring them. Available in TypeScript β‰₯ 2.1 (some require β‰₯ 4.5 / 5.4 β€” see Added tags).

What is TypeScript Utility Types Reference?

TypeScript Utility Types Reference documents all built-in TypeScript generic utility types: Partial, Required, Readonly, Record, Pick, Omit, Exclude, Extract, NonNullable, ReturnType, InstanceType, Parameters, ConstructorParameters, Awaited, and more. Each type includes a description, type signature, and concrete code examples showing input and output types.

TypeScript utility types are generic types provided in the standard library (lib.es5.d.ts and others) that transform existing types into new ones. They implement common type transformations that would otherwise require complex mapped types or conditional types. Understanding utility types is key to writing DRY type definitions β€” instead of duplicating type structures, you derive one from another: Partial to make all fields optional for update operations, Pick to create a subset type for API responses.

Beyond the built-in utility types, the TypeScript community has developed type-level programming patterns for complex transformations. The type-fest library by Sindre Sorhus and ts-toolbelt offer hundreds of additional utility types. TypeScript's 'type challenges' GitHub repository (type-challenges/type-challenges) is a popular way to learn advanced type manipulation.

How to Use

  1. Click any utility type name to see its type signature and description.
  2. View the 'Before / After' code examples to see how each type transforms an interface.
  3. Use the search box to find types by name or by what they do (e.g., 'optional', 'subset').
  4. Copy the example code snippets directly into your TypeScript project.
  5. See the 'When to use' notes to choose the right utility type for your situation.

Examples

Make all fields optional

Result: Partial β†’ { id?: number; name?: string; email?: string }

Extract specific fields

Result: Pick β†’ { id: number; email: string }

Get function return type

Result: ReturnType β†’ Promise

Frequently Asked Questions

What is the difference between Partial and Required?

Partial makes all properties of T optional (adds ? to every property). Used for update operations where only some fields may be provided. Required is the opposite β€” it makes all optional properties required (removes ? from every property). Used when you have a type with optional fields but a specific function needs all of them. Example: interface Config { host?: string; port?: number; } β€” Required gives { host: string; port: number }.

When should I use Pick vs Omit?

Pick creates a new type with only the specified keys from T. Omit creates a type with all keys of T except the specified ones. Choose Pick when you want a small subset of a large type (easier to list what you want). Choose Omit when you want almost everything except a few fields (easier to list what to exclude). Example: Pick (want exactly these two fields) vs Omit (want everything except sensitive fields).

What is the difference between Exclude and Omit?

Exclude works on union types β€” it removes members of union T that are assignable to U. Example: Exclude<'a'|'b'|'c', 'a'|'b'> β†’ 'c'. Omit works on object types β€” it removes properties K from object type T. They operate at different levels: Exclude filters union members, Omit filters object properties. Omit is actually implemented using Exclude internally: type Omit = Pick>.

What does NonNullable do?

NonNullable removes null and undefined from a type. Example: NonNullable β†’ string. Useful after null checks when you know a value is present but the type still includes null. Combined with type narrowing: function processUser(user: User | null) { if (user) { const safeUser: NonNullable = user; /* ... */ } }. In TypeScript 4.9+, the satisfies operator can also help express this without explicit casting.

What is the Awaited utility type?

Awaited recursively unwraps Promise types β€” it extracts the type that a Promise resolves to. Awaited> β†’ string. Awaited>> β†’ number (unwraps nested promises). Introduced in TypeScript 4.5 (2021) to replace the manual ReturnType + Promise unwrapping patterns. Use case: function getUser(): Promise β€” Awaited> gives you User. This is the correct way to extract the resolved type of async functions.

Related Tools