3 ms·
In a language like Rust or OCaml with exhaustive pattern matching on algebraic data types, the initial example is the recommended approach, because you will nev
by satvikpendem 4y ago
In a language like Rust or OCaml with exhaustive pattern matching on algebraic data types, the initial example is the recommended approach, because you will never miss a case, it forces you to think through all possible cases, where as the later refactored example in the article do not have such a constraint.
- qayxc 4y agoThe same is true for Typescript, hence the userType's restriction to 'customer' and 'admin'. Though the initial sample code is wrong anyway - note the missing "break" statements inside the switch.
- JoeyJoJoJr 4y agoIt’s not only true for Typescript, but often times necessary if you require dynamic behaviour that would otherwise be achieved through reflection.