What is variance in the context of TypeScript generics?

TypeScript Professional Hard

TypeScript Professional — Hard

What is variance in the context of TypeScript generics?

Key points

  • Variance determines how type safety is preserved in generic types
  • Covariant types allow subtyping relationships to be preserved
  • Contravariant types reverse the subtyping relationships
  • Invariant types strictly maintain the type relationships

Ready to go further?

Related questions