What does `type ReturnType = T extends (…args: any[]) => infer R ? R : never` do?

TypeScript Professional Hard

TypeScript Professional — Hard

What does `type ReturnType = T extends (…args: any[]) => infer R ? R : never` do?

Key points

  • This code snippet uses conditional types to extract the return type of a function.
  • It leverages TypeScript's type inference capabilities to determine the return type.
  • The `infer R` syntax is crucial for capturing the return type of the function.

Ready to go further?

Related questions