TypeScript Developer interview question · Most asked
Which built-in utility types do you use most, and what do they do?
Summary
Common ones: Partial<T>, Required<T>, Readonly<T>, Pick<T, K>, Omit<T, K>, Record<K, V>, Exclude<U, X>, Extract<U, X>, NonNullable<T>, ReturnType<F>, Parameters<F>, Awaited<T> and NoInfer<T> (5.4).
Longer Answer
They're built with mapped and conditional types. Example uses: Partial<User> for PATCH payloads, Omit<User, 'password'> for public DTOs, Record<Status, string> for exhaustive lookup tables, ReturnType<typeof createStore> to derive types from implementations, and Awaited<ReturnType<typeof fetchUser>> for async results.
Code Example
interface User { id: string; name: string; email: string; password: string }
type PublicUser = Omit<User, "password">;
type UserPatch = Partial<Pick<User, "name" | "email">>;
type StatusLabels = Record<"active" | "banned", string>;
async function fetchUser(id: string): Promise<PublicUser> { /* ... */ return null!; }
type Fetched = Awaited<ReturnType<typeof fetchUser>>; // PublicUser
Key Points
- Partial/Required/Readonly modify properties
- Pick/Omit select keys
- Record for maps with known keys
- ReturnType/Parameters/Awaited derive types
More most-asked TypeScript Developer questions
- What is TypeScript and what problems does it solve?
- What are the differences between `interface` and `type` aliases?
- Explain `any`, `unknown` and `never`.
- What is type narrowing and what techniques does TypeScript support?
- What are discriminated unions and why are they powerful?
- What are generics and how do constraints work?
- What is structural typing in TypeScript?
- What are mapped types? Show how `Partial` or `Readonly` could be implemented.