4 ms·
I'm critiquing the implementation shown in the blog, not your hypothetical implementation in typescript that I've never seen. That was not what you originally
by lacampbell 7y ago
I'm critiquing the implementation shown in the blog, not your hypothetical implementation in typescript that I've never seen.
That was not what you originally wrote:
The fact is that it's forcing a concept that can't be expressed in the language properly.
Your claim was that it cannot be expressed in the language properly, and I am disagreeing.
In nominal type systems like Rust/Haskell/F# you want to be able to match on the constructor. In typescript where '|' means something slightly different you need to fake a type constructor by adding a type: "variantname" property
You didn't answer the question, what useful pattern matching can you do with Either/Option? Give me pseudocode even.
Javascript doesn't support those things.
A few jsdoc comments and tsc command, and hey presto - it does.