Menu

Built-in Utility Types

Lesson 2: Built-in Utility Types

Which utility types should you know?

Utility Does Example result
Partial<T> Makes all properties optional Update payloads
Required<T> Makes all properties required Fully filled forms
Readonly<T> Makes all properties read-only Frozen config
Pick<T, K> Keeps only the listed properties `Pick<Product, 'id'
Omit&lt;T, K&gt; Removes the listed properties Omit&lt;Product, 'id'&gt; for creation
Record&lt;K, V&gt; Object with keys K and values V Lookup tables
Exclude&lt;U, X&gt; Removes members from a union Exclude&lt;Status, 'cancelled'&gt;
Extract&lt;U, X&gt; Keeps matching union members `Extract<Status, 'shipped'
NonNullable<T> Removes null and undefined `NonNullable<string
ReturnType&lt;F&gt; Return type of a function type ReturnType&lt;typeof getCart&gt;
Parameters&lt;F&gt; Parameter types as a tuple Parameters&lt;typeof addItem&gt;
Awaited&lt;T&gt; Unwraps a Promise Awaited&lt;Promise&lt;Order&gt;&gt; → Order

Example

@@CODE_BLOCK_0@@

How it works

  • Utility types are generic types built into TypeScript, written with mapped and conditional types (Lessons 3 and 4).
  • Deriving NewProduct and ProductUpdate from Product means adding a field to Product updates them all.
  • Awaited&lt;ReturnType&lt;typeof fn&gt;&gt; is a common way to get the resolved type of an async function without declaring it separately.

Common mistakes

Mistake Effect Fix
Using Partial&lt;Product&gt; for creation Required fields can be missing Use Omit for creation, Partial for updates
Omit&lt;T, 'nmae'&gt; with a typo No error: Omit accepts any string Double-check keys, or write a stricter helper
Readonly&lt;T&gt; expected to be deep Nested objects remain mutable Write a DeepReadonly type if needed

Key takeaways

  • Utility types derive variations of a type instead of copying it.
  • Omit for creation, Partial for updates, Pick for summaries.

Try it: From an Order interface, derive NewOrder, OrderUpdate, and OrderListItem types using utility types.


TypeScript Tutorial

J

Jebasta





Get in Touch For Details