News for hackers. Stuff that matters.
Re:Are unsound type systems wrong? by leshow on Saturday April 07, 2018 @02:30PM (#16782025)
I think another reason they added refinement types in the form of literal string types and literal number types was because there are no data constructors in TS & Flow either. This is a bit of speculation on my part.

For example, in lots of strongly typed languages when you make a sum type there's a constructor. haskell,

data Foo = Baz | Bar

or rust, enum Foo { Baz, Bar }

Baz and Bar are data constructors, they allow you to pattern match on them and make new values. In ts an equivalent sum type has to use a string/number refinement.

type Foo = { kind: "baz" } | { kind: "bar" }

This fits closer to js semantics and still allows sum types to be written. Unfortunately the pattern matching isn't anywhere near as good, but I applaud them for adding this to the language.

There are no comments on this comment yet.