Explain 'Variance' (Covariance and Contravariance) in TypeScript.
Updated May 4, 2026
Short answer
Variance describes how subtyping between complex types relates to subtyping between their component types.
Deep explanation
In TypeScript, most types are 'covariant' (e.g., if Dog extends Animal, then Array<Dog> is a subtype of Array<Animal>). However, function arguments are 'contravariant'. This means a function that accepts an Animal is a subtype of a function that accepts a Dog, because the Animal-accepting function can safely handle anything a Dog-accepting function can. Understanding this is crucial for writing safe generic interfaces and complex function overloads.
Unlock with a Pro subscription to view this section.
View pricingReal-world example
No real-world example available yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProCommon mistakes
No common mistakes listed yet.
Unlock with a Pro subscription to view this section.
Upgrade to ProFollow-up questions
No follow-up questions available yet.
Unlock with a Pro subscription to view this section.
Upgrade to Pro