Skip to main content
InterviewHubPRO
Section Overview
Q27

Question 27 of 50

Part 2: Advanced Type System & Metaprogramming (Mid-Level)

54%
TypeScript Master (50 Qs)•Part 2: Advanced Type System & Metaprogramming (Mid-Level)

What is Variance in TypeScript (Covariance vs Contravariance)?

junior LevelTypeScript

In Simple Words: Variance describes how subtyping of complex types relates to subtyping of their component types:

  • Covariance (Output positions): If Dog extends Animal, then Dog[] extends Animal[], and () => Dog extends () => Animal.
  • Contravariance (Input/Parameter positions): Function parameters are contravariant under strictFunctionTypes. (a: Animal) => void is assignable to (d: Dog) => void (a function that can handle any animal can safely handle a dog).