What is the benefit of pattern matching in a language where any value can be of any type at runtime? You can just pattern match by saying if (obj.type === 'foo') {}; if (obj.type === 'bar') {}; etc in JS, as long as you have set up the convention that you set the 'type' field, and practically this is just as good.
The real benefit of pattern matching is the compiler checking at least that you have valid cases, and ideally that you haven't missed any cases.
The real benefit of pattern matching is the compiler checking at least that you have valid cases, and ideally that you haven't missed any cases.