News for hackers. Stuff that matters.
Re:TypeScript 2.4 by victorNicollet on Wednesday June 28, 2017 @07:31AM (#14653220)
Explaining it to a five-year-old adds overhead that isn't really useful when you're in fact explaining to someone who knows about programming but has simply never heard about covariance and contravariance.

A function `X -> string` can be turned into a function `X -> object`: call it, take its string result and cast it to object. This is called covariant (latin co- for "together") because casting `string` to `object` also lets you cast `X -> string` to `X -> object`.

A function `object -> X` can turned into a function `string -> X`: take the string argument, cast it to object, and pass it to the function. This is called contravariant (latin contra- for "against") because casting `string` to `object` lets you cast `object -> X` to `string -> X`.

Re:TypeScript 2.4 by dotancohen on Thursday June 29, 2017 @01:39AM (#14661036)
Thanks, obviously your example is more concrete. GP's comment was good for introducing the idea and your comment is great for showing how the idea is useful.