News for hackers. Stuff that matters.
Re:TypeScript 3.5 by ElFitz on Wednesday May 29, 2019 @05:37PM (#20045807)
> There is no other programming language that has union types as powerful as TypeScript

How about Swift and OCaml? ReasonML comes to mind too. Haven't tried actively comparing any of them though.

Re:TypeScript 3.5 by tomp on Wednesday May 29, 2019 @06:06PM (#20046086)
OCaml/Reason have discriminated unions, which means that you have to explicitly specify which variant of the union you're using, such as

  type union = Bool of bool | Char of char | Nothing

  let (x, y, z) = (Nothing, Bool true, Char 'x')
Re:TypeScript 3.5 by saagarjha on Wednesday May 29, 2019 @08:44PM (#20047265)
Is this not what enums with associated values are?
Re:TypeScript 3.5 by tomp on Thursday May 30, 2019 @02:02AM (#20048783)
Probably... but in any case TypeScript also supports naked (edit: I just made up the name) unions, where you don't need to declare them upfront, and where values of different types can be included directly. Such as:

  let a = random() ? 'a' : 1
TypeScript infers type

  string | number
Re:TypeScript 3.5 by marton78 on Thursday May 30, 2019 @06:54AM (#20049936)
This is still a discriminated union, only that the discriminator is provided by Javascript and is thus hidden: it's `typeof`.
Re:TypeScript 3.5 by tomp on Thursday May 30, 2019 @08:17AM (#20050387)
Yeah, that's the runtime perspective... but for the type system, they're different... with the "naked" union being much harder (as they're non-algebraic - `a | b | b` always equals `a | b` and might even equal just `a` for some values of `a` and `b`)
Re:TypeScript 3.5 by spion on Thursday May 30, 2019 @12:09PM (#20052632)
No, this works on any overlapping types too - even unsound combinations such as `T | Array<T>`
Re:TypeScript 3.5 by ElFitz on Friday May 31, 2019 @03:34AM (#20058896)
Interesting! Thanks!
Re:TypeScript 3.5 by kbp on Wednesday May 29, 2019 @06:58PM (#20046581)
What features are you thinking of in those languages? I don't know Swift but I can't think of anything comparable in OCaml.
Re:TypeScript 3.5 by ElFitz on Friday May 31, 2019 @03:41AM (#20058932)
Sorry; I don't have much of an answer here.

I merely know from experience that they have a pretty good type system, but not much more. So I asked :-)

Answers have been enlightening