News for hackers. Stuff that matters.
Re:TypeScript’s quirks: How inconsistencies make the languag... by MaulingMonkey on Saturday February 01, 2020 @03:38AM (#22209480)
Note that you can only pass Cat to a Dog function if:

* All fields of Dog are also present in Cat, with compatible type signatures

* All functions of Dog are also present in Cat, with comaptible type signatures

"compatible type signatures" does seem to leave some suprising co/contravariance holes still when using wider union types, but C#/Java arrays also have co/contravariance holes and we don't automatically write off their entire type systems because of it. Or, well, at least I don't ;).

As a meaningless point of ancedata: Making these types sufficiently equivalent to fall through this type safety hole appears to be rare enough that I've never done so by accident - allowing me to be suprised by the article's example of passing a class Cat to a class Dog-accepting function being legal. While typescript has never been my primary dayjob, it's been a significant secondary part of my dayjob and hobby junk.

(EDIT: Minor clarifications)

Re:TypeScript’s quirks: How inconsistencies make the languag... by Kinrany on Saturday February 01, 2020 @06:45AM (#22210017)
Re:TypeScript’s quirks: How inconsistencies make the languag... by carlmr on Saturday February 01, 2020 @05:31AM (#22209803)
C# has a great type system, but everything has ToString() and sometimes that doesn't output something sensible, and gets implicitly converted, leading to garbage.

Still much better than working in C or some other weakly typed languages.