
Once you know the basic types, interviews move on to generics and the type tools that give TypeScript its power: keyof, utility types like Partial and Omit, mapped types and conditional types. This set checks if you can read and make sense of the types you see in real React and Node.js projects.
How to practise: read each question and tap the option you think is correct. You will see right away whether you got it, along with a short explanation, and your score is tracked at the bottom of the screen. This set has 15 questions.
Topics covered in this set
- Generic functions and constraints with extends
- keyof, typeof and indexed access types
- Built-in utility types: Partial, Required, Pick, Omit, Record, ReturnType
- Mapped types and key remapping
- Conditional types and infer
- satisfies and type assertions
TypeScript MCQs with answers and explanations
Q1. What does the generic constraint do in this function?
function getLength<T extends { length: number }>(x: T) {
return x.length;
}
a) T is always number
b) T can be any type at all
c) T must be an array
d) T must be a type that has a numeric length property
Q2. Given type User = { id: number; name: string }, what is keyof User?
a) number | string
b) User[]
c) "id" | "name"
d) string
Q3. What is User["name"] (an indexed access type) for the same User type?
a) string
b) "name"
c) User
d) unknown
Q4. Which utility type makes every property of T optional?
a) Partial<T>
b) Readonly<T>
c) Required<T>
d) Pick<T, K>
Q5. What is the result of Omit<User, "id">?
a) { id: number }
b) User | "id"
c) never
d) { name: string }
Q6. What does Record<"en" | "hi", string> describe?
a) An object with exactly the keys en and hi, both of type string
b) A tuple
c) A Map object
d) An array of two strings
Q7. How do you get the type of a value, for example a config object, without writing it by hand?
a) config as type
b) instanceof config
c) keyof config
d) typeof config in a type position
Q8. What does ReturnType<typeof fetchUser> give you?
a) The type that fetchUser returns
b) A Promise always
c) The parameter types of fetchUser
d) The name of the function
Q9. What does this mapped type produce?
type Flags<T> = { [K in keyof T]: boolean };
type F = Flags<{ a: string; b: number }>;
a) { K: boolean }
b) boolean[]
c) { a: string; b: number }
d) { a: boolean; b: boolean }
Q10. What is IsString<42>?
type IsString<T> = T extends string ? "yes" : "no";
a) "no"
b) never
c) boolean
d) "yes"
Q11. What does the infer keyword do in a conditional type?
a) Turns off type inference
b) Declares a type variable to capture part of a matched type, such as an array element or a promise value
c) Imports a type from another file
d) Asserts a type at runtime
Q12. What happens when a conditional type receives a union, as in IsString<string | number>?
a) It distributes over each member, giving "yes" | "no"
b) It is a compile error
c) It returns "yes" because one member matches
d) It always returns never
Q13. What is the advantage of satisfies over a type annotation in const theme = { primary: "#6d28d9" } satisfies Record<string, string>?
a) It converts the object at runtime
b) It checks the value against the type but keeps the more specific inferred type of the object
c) It removes the need for strict mode
d) It makes the object readonly
Q14. Which statement about a generic React component like function List<T>(props: { items: T[]; render: (item: T) => ReactNode }) is true?
a) T is inferred from the items prop, so render receives correctly typed items
b) Generic components are not allowed in TSX
c) T must be specified manually every time
d) T is always any
Q15. Why is as (a type assertion) considered risky?
a) It slows down the compiler
b) It overrides the compiler's inferred type without any runtime check, so wrong assertions cause runtime bugs
c) It is removed in strict mode
d) It only works on primitives
Quick revision notes
- Use extends on a generic to ask for a minimum shape.
- keyof gives keys, typeof gives a value's type, T[K] gives a property's type.
- Partial, Required, Readonly, Pick, Omit and Record cover most day-to-day needs.
- Conditional types run over each union member. infer pulls out part of a type.
- Use satisfies instead of an annotation when you want the check but also want to keep literal types.
Frequently asked questions
Do I need to memorise how utility types are implemented?
No. But you should know that most of them are simple mapped or conditional types. Interviewers sometimes ask you to write Partial or Pick yourself.
When should I use generics?
When a function, hook or component works the same way for many types, and you want the output type to follow the input type. A typed fetch helper or a reusable list component are good examples.
What is the difference between unknown and a generic T?
unknown means "could be anything, check it before use". A generic T means "one specific type that the caller picks", so the compiler can link the input and output types.
Comments
Post a Comment