Challenge your understanding of advanced mapped and conditional types, including type inference, property modifiers, and complex pattern transformations in modern type systems. This quiz is ideal for those seeking to deepen their proficiency in advanced generics and type-level programming concepts.
Given the mapped type 'type OptionalPropsu003CTu003E = { [K in keyof T]?: T[K] }', what effect does this have if T is defined as 'type T = { a: number; b: string }'?
Explanation: The mapped type uses the optional modifier '?', so all properties in T, including 'a' and 'b', become optional in the resulting type. The second option is incorrect because both fields, not just 'b', are affected. The third option is incorrect because the mapped type changes their optionality rather than keeping them required. The fourth distractor is incorrect since no properties are removed; all are retained as optional.
In the definition 'type ElementTypeu003CTu003E = T extends (infer U)[] ? U : T', what is ElementTypeu003C[boolean, boolean]u003E?
Explanation: The conditional type checks if T fits the array pattern; for [boolean, boolean], T extends (infer U)[] resolves U as boolean, resulting in boolean. Option 'boolean[]' is incorrect because we extract the element type, not the array type. 'never' would be the outcome only if the condition failed. 'unknown' is a generic fallback and not correct here.
Which mapped type pattern correctly transforms all string property names to uppercase for an object type T?
Explanation: The correct syntax uses 'as Uppercaseu003CK u0026 stringu003E' to explicitly remap keys to their uppercase forms. The second and third options use invalid type utility names ('UpperCase' and 'UPPER'), which do not exist. The fourth option, 'Capitalize', converts only the first letter to uppercase, not the entire key as required.
Given the type 'type ToArrayu003CTu003E = T extends any ? T[] : never', what is the result of ToArrayu003Cnumber | stringu003E?
Explanation: Conditional types in this form are distributive over unions, so both 'number' and 'string' are individually wrapped into arrays, producing 'number[] | string[]'. '(number | string)[]' would arise if the type was not distributive. 'never' and 'undefined' are incorrect as the type always produces an array form for valid inputs.
Which mapped type pattern correctly removes readonly modifiers from all properties of a type T?
Explanation: Using '-readonly' before the property key in the mapped type removes the readonly modifier from all properties. The second option incorrectly attempts to add a 'readonly:' property inside the type, which is invalid. The third option removes optional modifiers, not readonly. The fourth distractor references a nonexistent 'Mutable' utility.