Sample questions
Question 1Easy
What does Partial<User> produce?
interface User { id: number; name: string }
type Draft = Partial<User>;
const d: Draft = {};
- User with every property made read-only
- User with every property allowed to be null
- Only the properties of User that are optional
- 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
- Partial<T> maps every property of T to optional.
- So Partial<User> is { id?: number; name?: string }.
- 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";
- Error: name is a read-only property
- No error; Readonly only affects arrays
- No error; it fails only at runtime
- 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
Readonly(T) marks every property of T as read-only.- u.name is therefore read-only, so the assignment is rejected at compile time.
- No runtime freezing is involved.
- 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?
- Exclude<User, "password">
- Partial<User, "password">
- Pick<User, "password">
- 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
Omit(T, K) builds a type with every key of T except K.- Here K is 'password', so password is removed and all other keys stay.
- Exclude works on union members, not on object keys.
- 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 }
- { email: string }
- { id: number; name: string }
- { id?: number; name?: string }
- "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
Pick(User, 'id' | 'name') keeps only the listed keys.- It keeps their original types, so id is number and name is string.
- Email is dropped.
- 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>;
- typeof Engine
- new () => Engine
- Engine
- 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
- typeof Engine is the constructor type.
- InstanceType extracts what new returns.
- 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 };
- No error; b defaults to 0
- Error: Record needs string keys
- No error; Record keys are optional
- 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
Record('a' | 'b', number) creates a required property for both a and b.- The value { a: 1 } has no b.
- A required property is missing, so TypeScript reports an error about b.
- 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>?
- string | number | boolean
- number
- string | boolean
- 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
Extract(T, U) keeps the members of T that are assignable to U.- T is string | number | boolean and U is string | boolean.
- String and boolean are kept, and number is dropped, so the result is string | boolean.
- 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>;
- ReturnType only works on arrow functions
- f is a value; the type needs typeof f
- f must declare an explicit return type
- 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
ReturnType(T) expects a type argument.- F is a value, the function itself, and not a type.
- To refer to its type, write typeof f, which gives
ReturnType(typeof f). - 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>>>?
- unknown
- Promise<number>
- number
- 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
Awaited(T) unwraps promises, including nested promises.- Promise<
Promise(number)> unwraps to Promise(number), then to number. - So the result is number.
- 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
- Both lines
- Only line 2
- Neither line
- 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
Omit(User, 'nope') is allowed, because Omit does not require the key to exist.Pick(User, 'nope') requires its key to be a key of User.- 'nope' is not a key of User, so line 2 fails.
- 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 →