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.
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`.