What does the following type produce and how does it work? type Zip = T extends [infer TH, …infer TT] ? U extends [infer UH, …infer UT] ? [[TH, UH], …Zip] : [] : [];

TypeScript Professional Hard

TypeScript Professional — Hard

What does the following type produce and how does it work? type Zip = T extends [infer TH, …infer TT] ? U extends [infer UH, …infer UT] ? [[TH, UH], …Zip] : [] : [];

Key points

  • Zip function pairs elements from T and U
  • Resolves at the type level
  • Stops at the shorter tuple
  • Mimics Python's zip behavior

Ready to go further?

Related questions