Variance and Generic Assignability
Whether Box<Dog> is assignable to Box<Animal> depends on how T is used: output positions are covariant, input positions contravariant, both invariant. TypeScript infers variance structurally (with optional in/out annotations to declare it), and method parameters are checked bivariantly for pragmatic compatibility — a deliberate soundness hole.
This Concept is waiting for its first lesson!
Whether Box<Dog> is assignable to Box<Animal> depends on how T is used: output positions are covariant, input positions contravariant, both invariant. TypeScript infers variance structurally (with optional in/out annotations to declare it), and method parameters are checked bivariantly for pragmatic compatibility — a deliberate soundness hole.
Are you a teacher? Sign in to start contributing.
Sign In