News for hackers. Stuff that matters.
Re:TypeScript for Pythonistas by tshaddox on Friday December 17, 2021 @04:17PM (#29598466)
> Type guards (for things like overloads) can also be a bit weird to write, for instance you can't really do an "instanceof" because that information is lost at run time

Isn’t the normal way to do this in TS to use discriminated unions, where you just store the type right there on the object as a string (perhaps in a key called “tag” or “type”)? I love discriminated unions, and needing to explicitly carry around that discriminator is a bit awkward coming from, say, OCaml, but it’s still my default way of modeling most things in TS.

There are no comments on this comment yet.