What does the following type-level operation produce? type Head = T extends [infer H, …any[]] ? H : never;

TypeScript Associate Hard

TypeScript Associate — Hard

What does the following type-level operation produce? type Head = T extends [infer H, …any[]] ? H : never;

Key points

  • This operation uses conditional types to check if T is a tuple with at least one element.
  • The `infer` keyword captures the type of the first element.
  • The `never` type is returned if T is an empty tuple.

Ready to go further?

Related questions