TypeScript Generics, Inference & Type-Level Programming
Two clusters in one quiz: Generics & Inference (when TS infers vs. when you must annotate, extends constraints, defaults, and why an unconstrained <T> leaks unknown) and Type-Level Programming (conditional types, infer, mapped & template-literal types). Read gnarly utility types and predict exactly what they resolve to. Every type-resolution claim was verified by compiling it with tsc 6.0 using Expect<Equal<…>> assertions.
Questions
- Not answered. What type does
wrap("hi")produce? - Not answered. With a
consttype parameter, what is the type ofx? - Not answered. An uninferable type parameter with a default — what is
b? - Not answered. What does
ToArray<string | number>resolve to? - Not answered. Does
Wrap<boolean>collapse toboolean[]? - Not answered. A gnarly one: what is
Rwhen the sameinfer Usits in two parameter slots? - Not answered. What shape does
Getters<{ name: string; age: number }>produce? - Not answered. Which statements about
NoInfer<T>are true? - Not answered. Given this constrained
pluck, which statements are true? - Not answered. An unconstrained
<T>that can't be inferred falls back to which type? - Not answered. What does
Head<"a.b.c">resolve to? - Not answered. Predict this recursive utility: what is
Flatten<number[][][]>?