Utility Types Questions with Answers

18 practice questions on Utility Types (TypeScript) with answers and step-by-step solutions. Try 10 samples below, then practise all 18 free in the AptiNest app.

Sample questions

Question 1Easy

What does Partial<User> produce?

interface User { id: number; name: string }
type Draft = Partial<User>;
const d: Draft = {};
  1. User with every property made read-only
  2. User with every property allowed to be null
  3. Only the properties of User that are optional
  4. User with every property optional

Answer: D. User with every property optional

Explanation

Partial<T> maps over T and adds? to each property, which suits update payloads where any subset of fields may be sent.

Step-by-step solution

  1. Partial<T> maps every property of T to optional.
  2. So Partial<User> is { id?: number; name?: string }.
  3. An empty object {} is therefore valid.

Why the other options are wrong

  • A. That is Readonly<User>.
  • B. Optional is not the same as null.
  • C. Partial affects all properties, not only already-optional ones.

Tip: Partial = all optional, Required = none optional.

Question 2Easy

What does TypeScript report for the second line?

const u: Readonly<{ name: string }> = { name: "Asha" };
u.name = "Ravi";
  1. Error: name is a read-only property
  2. No error; Readonly only affects arrays
  3. No error; it fails only at runtime
  4. Error: u is declared with const

Answer: A. Error: name is a read-only property

Explanation

Readonly<T> marks every property readonly, so assigning to u.name is rejected at compile time. No runtime freezing happens.

Step-by-step solution

  1. Readonly(T) marks every property of T as read-only.
  2. u.name is therefore read-only, so the assignment is rejected at compile time.
  3. No runtime freezing is involved.
  4. The answer is option A.

Why the other options are wrong

  • B. Readonly applies to object properties, not only arrays.
  • C. The error is reported at compile time, not at runtime.
  • D. The problem is the property, not the const variable u.

Tip: Readonly<T> is compile-time only; it blocks writes to each property.

Question 3Easy

Which type removes the password property from User and keeps the rest?

  1. Exclude<User, "password">
  2. Partial<User, "password">
  3. Pick<User, "password">
  4. Omit<User, "password">

Answer: D. Omit<User, "password">

Explanation

Omit<T, K> builds an object type with every key of T except K. Exclude works on union members, not object keys.

Step-by-step solution

  1. Omit(T, K) builds a type with every key of T except K.
  2. Here K is 'password', so password is removed and all other keys stay.
  3. Exclude works on union members, not on object keys.
  4. The answer is option D, Omit(User, 'password').

Why the other options are wrong

  • A. Exclude filters union members; it does not remove a key from an object type.
  • B. Partial takes one type argument, and it makes properties optional.
  • C. Pick<User, 'password'> keeps only password, which is the opposite.

Tip: Omit removes keys from an object type; Pick keeps only the listed keys.

Question 4Easy

What type does Pick<User, "id" | "name"> produce for the interface below?

interface User { id: number; name: string; email: string }
  1. { email: string }
  2. { id: number; name: string }
  3. { id?: number; name?: string }
  4. "id" | "name"

Answer: B. { id: number; name: string }

Explanation

Pick<T, K> keeps only the listed keys, with their original types and modifiers.

Step-by-step solution

  1. Pick(User, 'id' | 'name') keeps only the listed keys.
  2. It keeps their original types, so id is number and name is string.
  3. Email is dropped.
  4. The answer is option B, { id: number; name: string }.

Why the other options are wrong

  • A. Pick keeps the listed keys, not the unlisted one.
  • C. Pick keeps the required modifiers, so the properties are not optional.
  • D. Pick returns an object type with the keys, not a union of key names.

Tip: Pick keeps the listed keys with their types and modifiers.

Question 5Medium

What is I?

class Engine { start() {} }
type I = InstanceType<typeof Engine>;
  1. typeof Engine
  2. new () => Engine
  3. Engine
  4. object

Answer: C. Engine

Explanation

typeof Engine is the constructor type. InstanceType extracts the type of the object that constructor creates.

Step-by-step solution

  1. typeof Engine is the constructor type.
  2. InstanceType extracts what new returns.
  3. That is Engine.

Why the other options are wrong

  • A. That is the constructor, not the instance.
  • B. That is a construct signature.
  • D. The class instance type is more specific.

Tip: ReturnType for functions, InstanceType for classes.

Question 6Medium

What does TypeScript report for this line?

const r: Record<"a" | "b", number> = { a: 1 };
  1. No error; b defaults to 0
  2. Error: Record needs string keys
  3. No error; Record keys are optional
  4. Error: property b is missing

Answer: D. Error: property b is missing

Explanation

Record<K, V> creates a required property for every key in K, so both a and b must be present.

Step-by-step solution

  1. Record('a' | 'b', number) creates a required property for both a and b.
  2. The value { a: 1 } has no b.
  3. A required property is missing, so TypeScript reports an error about b.
  4. The answer is option D.

Why the other options are wrong

  • A. Missing properties do not default to 0; they are required.
  • B. Record accepts string literal keys, so there is no such error.
  • C. The keys are required, not optional.

Tip: Record<K, V> makes every key in K required unless you use Partial.

Question 7Medium

What is Extract<string | number | boolean, string | boolean>?

  1. string | number | boolean
  2. number
  3. string | boolean
  4. never

Answer: C. string | boolean

Explanation

Extract<T, U> keeps the members of T that are assignable to U. It is the opposite of Exclude.

Step-by-step solution

  1. Extract(T, U) keeps the members of T that are assignable to U.
  2. T is string | number | boolean and U is string | boolean.
  3. String and boolean are kept, and number is dropped, so the result is string | boolean.
  4. The answer is option C.

Why the other options are wrong

  • A. Extract removes number, so the full union is not the result.
  • B. Number is the member removed, not the one kept.
  • D. String and boolean both match U, so the result is not never.

Tip: Extract keeps matches; Exclude removes them.

Question 8Medium

Why does this code fail to compile?

function f() { return 1; }
type R = ReturnType<f>;
  1. ReturnType only works on arrow functions
  2. f is a value; the type needs typeof f
  3. f must declare an explicit return type
  4. ReturnType takes two type arguments

Answer: B. f is a value; the type needs typeof f

Explanation

Type arguments must be types. typeof f turns the function value into its type, so ReturnType<typeof f> works.

Step-by-step solution

  1. ReturnType(T) expects a type argument.
  2. F is a value, the function itself, and not a type.
  3. To refer to its type, write typeof f, which gives ReturnType(typeof f).
  4. The answer is option B.

Why the other options are wrong

  • A. ReturnType works on any function type, not only arrow functions.
  • C. F does not need an explicit return type; it is inferred as number.
  • D. ReturnType takes one type argument, not two.

Tip: To get a function's type from a value, use typeof before the name.

Question 9Hard

What is Awaited<Promise<Promise<number>>>?

  1. unknown
  2. Promise<number>
  3. number
  4. Promise<Promise<number>>

Answer: C. number

Explanation

Awaited unwraps promises recursively, just as await does at runtime, so nested promises collapse to number.

Step-by-step solution

  1. Awaited(T) unwraps promises, including nested promises.
  2. Promise<Promise(number)> unwraps to Promise(number), then to number.
  3. So the result is number.
  4. The answer is option C.

Why the other options are wrong

  • A. The type is fully known, so it is not unknown.
  • B. Promise<number> is only one layer; Awaited unwraps all of them.
  • D. Awaited removes every promise layer, so the result has no Promise left.

Tip: Awaited<T> unwraps all promise layers, like nested await does at runtime.

Question 10Hard

Which line fails to compile?

interface User { id: number; name: string }
type A = Omit<User, "nope">;   // line 1
type B = Pick<User, "nope">;   // line 2
  1. Both lines
  2. Only line 2
  3. Neither line
  4. Only line 1

Answer: B. Only line 2

Explanation

Pick constrains K to keyof T, so an unknown key is an error. Omit's K is only constrained to string | number | symbol, so omitting a missing key is allowed.

Step-by-step solution

  1. Omit(User, 'nope') is allowed, because Omit does not require the key to exist.
  2. Pick(User, 'nope') requires its key to be a key of User.
  3. 'nope' is not a key of User, so line 2 fails.
  4. The answer is option B, only line 2.

Why the other options are wrong

  • A. Line 1 compiles, because Omit accepts any key type.
  • C. Line 2 does not compile, so the answer is not neither.
  • D. Line 1 compiles; only line 2 fails.

Tip: Pick needs keys that exist on the type; Omit accepts any key and ignores missing ones.

Practise all 18 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all TypeScript topics · All topics