News for hackers. Stuff that matters.
Re:TypeScript’s quirks: How inconsistencies make the languag... by paavohtl on Saturday February 01, 2020 @05:01AM (#22209713)
As a long time TypeScript user, I do think this is a design mistake with the language. For example, it breaks instanceof checks.

However:

- The language primarily uses structural typing. If two classes are compatible, it's not completely unreasonable to expect them to also behave in a structural way (though I would prefer them not to).

- Adding a private field to a class makes it work as a nominal type (https://michalzalecki.com/nominal-typing-in-typescript/#appr...). It feels a bit hacky and it's not very well documented, but you could argue that until a class has some private state you can't publicly access, there's no reason to prevent you from declaring a compatible class.

- From my experience idiomatic TypeScript rarely uses classes, the primary exception being React components. In teams I've been a part of we've always written TypeScript (and JavaScript) like an (impure) functional language, taking full advantage of ADTs, simple structurally typed data and more-or-less pure functions.

Re:TypeScript’s quirks: How inconsistencies make the languag... by The_rationalist on Saturday February 01, 2020 @08:44AM (#22210458)
taking full advantage of ADTs What? There is no clean way to switch on the types of an ADT on typescript, I believe.
Re:TypeScript’s quirks: How inconsistencies make the languag... by alexcole on Saturday February 01, 2020 @08:43PM (#22214584)
Well discriminated unions are TypeScript's implementation of ADTs (but whether they are "clean" is could be debated)