Back to the Catalog
typescript
javascript

TypeScript Generics, Inference & Type-Level Programming

12 questions

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

  1. Not answered. What type does wrap("hi") produce?
  2. Not answered. With a const type parameter, what is the type of x?
  3. Not answered. An uninferable type parameter with a default — what is b?
  4. Not answered. What does ToArray<string | number> resolve to?
  5. Not answered. Does Wrap<boolean> collapse to boolean[]?
  6. Not answered. A gnarly one: what is R when the same infer U sits in two parameter slots?
  7. Not answered. What shape does Getters<{ name: string; age: number }> produce?
  8. Not answered. Which statements about NoInfer<T> are true?
  9. Not answered. Given this constrained pluck, which statements are true?
  10. Not answered. An unconstrained <T> that can't be inferred falls back to which type?
  11. Not answered. What does Head<"a.b.c"> resolve to?
  12. Not answered. Predict this recursive utility: what is Flatten<number[][][]>?