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 pricing

Real-world example

No real-world example available yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

Common mistakes

No common mistakes listed yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

Follow-up questions

No follow-up questions available yet.

Unlock with a Pro subscription to view this section.

Upgrade to Pro

More TypeScript interview questions

View all →