What is the purpose of the ‘infer’ keyword in a conditional type?

TypeScript Professional Medium

TypeScript Professional — Medium

What is the purpose of the ‘infer’ keyword in a conditional type?

Key points

  • 'Infer' keyword enables TypeScript to automatically deduce a type variable
  • This type variable is inferred from the matched type in the conditional type
  • It helps in extracting and using the inferred type within the conditional type

Ready to go further?

Related questions