Recall & Review
beginner
What is a mapped type in TypeScript?
A mapped type creates a new type by transforming each property of an existing type. It uses syntax like
{ [K in keyof T]: ... } to loop over keys.Click to reveal answer
intermediate
How can you apply a transformation deeply to nested objects using mapped types?
You can use recursive mapped types that check if a property is an object and then apply the mapped type again to that property, enabling deep transformations.
Click to reveal answer
advanced
Explain the purpose of the
infer keyword in deep mapped types.infer helps extract types inside conditional types. It can be used to capture inner types during recursion for deep transformations.Click to reveal answer
intermediate
What does this TypeScript type do?<br>
type DeepReadonly<T> = { readonly [K in keyof T]: T[K] extends object ? DeepReadonly<T[K]> : T[K] };It makes all properties of
T deeply readonly, meaning nested objects' properties are also readonly recursively.Click to reveal answer
intermediate
Why do we need to check if a property is an object before applying deep mapped types?
Because primitive types like string or number should not be transformed recursively. Checking prevents errors and infinite recursion.
Click to reveal answer
What does
keyof T represent in a mapped type?✗ Incorrect
keyof T is a union of all property names (keys) of type T.Which TypeScript feature allows a mapped type to apply itself recursively?
✗ Incorrect
Conditional types let you check if a property is an object and then apply the mapped type recursively.
What is the main risk if you don't check for object types in deep mapped types?
✗ Incorrect
Without checking, recursion can continue infinitely causing errors.
What does the
readonly modifier do in a mapped type?✗ Incorrect
readonly makes properties immutable after initialization.Which syntax correctly defines a mapped type?
✗ Incorrect
Mapped types use
{ [K in keyof T]: ... } syntax to transform properties.Describe how to create a deep transformation mapped type in TypeScript.
Think about looping over keys and applying the type again if the property is an object.
You got /4 concepts.
Explain why deep mapped types are useful in real-world TypeScript projects.
Consider how nested data structures benefit from consistent type changes.
You got /4 concepts.