DEV Community 👩‍💻👨‍💻

Discussion on: Tagged Unions and ReScript Variants

hoichi profile image
Sergey Samokhov

Thank you, Patrick, for this down-to-earth writeup. Nice balance of safety and practicality.

Without any return statements or other trickery, TS apparently does not do any exhaustive checks within switches

Yeah, the shortest way I've found was an IIFE and a type annotation, i.e.:

let foo: Foo = (() => switch (expr.kind) {
  case "doc": return ...;
  case "text": return ...;
  case "paragraph": return ...;
Enter fullscreen mode Exit fullscreen mode

Workable, but much noisier than ReScript. And the lack of nested patterns is no fun. So that's 1 for ReScript :)