Comment

Comment by sfvisser

It's a neat trick and I've used similar patterns in some of our projects, but in the end it doesn't buy you much over a `switch (x.kind) { ... }`. (Except your matcher can be used as a proper expression which is nice obviously)

But you don't have proper pattern nesting, fall-through semantics and it's not clear (to me yet) how to extend to matching on multiple values. Try implementing an equality function on a sum-type using pattern matching.

Having actual proper pattern matching added to TS would be such a great addition. Especially with full support of the control flow analysis.

parent sfvisser 7 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton