← Learning Hub
Intermediate

Utility Types: Partial, Pick, Omit, Record

TypeScript has built-in helpers that make new types from existing ones, so you don't repeat yourself.

Utility types build new types from existing ones, so you don't repeat yourself: a form where every field is optional (Partial), a card showing only some fields (Pick), a new item without its server-made id (Omit).

Example
You can edit this code.

Record: an object used as a dictionary

Example
You can edit this code.

More helpers

  • Required<T> - every property must be there
  • Readonly<T> - nothing can be changed
  • ReturnType<typeof fn> - the type a function returns
  • NonNullable<T> - removes null and undefined
Example
You can edit this code.
Key points
  • Partial, Required, Readonly change all properties.
  • Pick and Omit keep or drop properties.
  • Record<K, V> describes dictionaries.

📝 Test yourself

1. Which makes every property optional?
2. Omit<Product, "id"> gives you...
3. Fill in the helper for a dictionary of string keys to numbers:
const stock: <string, number> = {};