TypeScript utility types vocabulary

  • Readonly<T> — all properties become read-only at compile time; assignment errors on any property
  • Pick<T, K> — subtype with only the listed keys; Omit<T, K> — subtype with all keys except listed
  • ReturnType<typeof fn> — infers the return type; typeof converts a value to its type
  • Parameters<typeof fn> — extracts parameter types as a tuple; use with rest spread to forward calls
  • Awaited<T> — unwraps Promise<T> to T; useful with ReturnType for async functions

Question 0 of 5

What does Readonly<Config> prevent?

interface Config { apiUrl: string; timeout: number; retries: number; } const config: Readonly<Config> = { apiUrl: "https://api.example.com", timeout: 5000, retries: 3, }; config.apiUrl = "https://other.com"; // Error! config.timeout = 10000; // Error!