Codington
0 of 7 problems solved0%

Creating Types from Types (Utility Patterns)

7 exercises

Utility types help you reshape and remix existing types without rewriting them:

type User = { id: number; name: string; email: string }; type UserPreview = Pick<User, 'id' | 'name'>; // { id, name } type PartialUser = Partial<User>; // All properties optional type ReadonlyUser = Readonly<User>; // Can't modify properties

They're building blocks for safer refactors and clearer intent.

Essential utility types:

Slicing objects:

  • Pick<T, Keys> – Keep only specific properties
  • Omit<T, Keys> – Remove specific properties

Adjusting optionality:

  • Partial<T> – Make all properties optional
  • Required<T> – Make all properties required

Other patterns:

  • Readonly<T> – Make properties read-only
  • Record<Keys, Type> – Build dictionary from keys and value type
  • ReturnType<F> – Extract function return type
  • Parameters<F> – Extract function parameter types as tuple

In this category, you'll:

  • Use Pick and Omit to create focused types from larger ones
  • Apply Partial and Required to adjust optionality
  • Use Readonly to communicate immutability
  • Build dictionaries with Record<K, V>
  • Extract types from functions with ReturnType and Parameters

These patterns help you connect APIs without duplicating type declarations, making refactoring safer and code more maintainable.

CodingtonCodington

© 2025 Codington. Built with TypeScript, TanStack Start and a lot of console.log().