Remix.run Logo
fourthark 11 hours ago

It will get pattern matching when JS does. Not certain yet but in progress.

https://github.com/tc39/proposal-pattern-matching

ibejoeb 11 hours ago | parent [-]

That proposal is really dragging though. And typescript needs as much work because that's where the real power is. We need discern thing like

    match (x) {
      "bob": ...,
      string: ...,
      () => Promise<void>: ...,
      () => Promise<string>: ...,
    }
with exhaustiveness checking for it to be truly useful.
ameliaquining 9 hours ago | parent [-]

Discriminating a function or promise based on return type is never going to work, because JavaScript is dynamically typed and TypeScript erases types at compile time, so there's no way to know at runtime what type a function or promise is going to return.