TypeScript · Middle · Question 7 of 75
What does infer do in type ElementType<T> = T extends (infer U)[] ? U : never?
- ✓Correct answer: Declares a type variable
Uthat TS infers from matching the pattern - 2Asks the compiler for the array element type at runtime
- 3Makes
Uan optional generic parameter defaulting tounknown
Explanation
infer is used only in the extends part of a conditional type: TS matches T against the pattern and "captures" the needed part. ElementType<string[]> → string. That's how ReturnType, Parameters and Awaited work.