On How TypeScript Handles Variance
Learn to understand TypeScript's handling of variance in its type system. This lesson explains key concepts like covariant, contravariant, invariant, and bivariant types using interface examples. You will grasp how these variances affect type acceptance and the structural typing system of TypeScript.
We'll cover the following...
We'll cover the following...
Type system variances
TypeScript variances use the nomenclature of another language, which is confusing by nature. It’s not something you must master since the compiler will stop you from doing anything crazy.
However, it’s good to understand before having the compiler manage the complexity for us. Before getting started, let’s create some interfaces to examine how TypeScript handles (or doesn’t handle) covariant, contravariant, bivariant, ...