What does the following type compute? type Tail = T extends [any, …infer Rest] ? Rest : never;

TypeScript Associate Hard

TypeScript Associate — Hard

What does the following type compute? type Tail = T extends [any, …infer Rest] ? Rest : never;

Key points

  • Conditional types in TypeScript allow for type inference based on a condition.
  • The infer keyword is used to capture and infer a type within a conditional type.
  • The expression T extends [any, ...infer Rest] checks if T is a tuple and extracts the rest of the elements.
  • The : never part handles the case of an empty tuple.

Ready to go further?

Related questions