Comment

Comment by spir

Good call. I love TypeScript, and wouldn't build a web app of even small scope without a typing solution at least as good as TypeScript, and it's the best.

But, as you say, pattern matching sum types is a weak point in practical use of TypeScript.

Since the types only exist at compile time, maybe there could be a heavier opt-in system that uses something like Symbols to do pattern matching:

  matchable type Shape = Circle | Square | Triangle;
  const myShape: Shape;
  match myShape {
    // uses symbol magic under the hood, eg. if (SymbolShapeCircle in o)
    case (c: Circle) { ... }
    case (other: Triangle | Square) { ... }
  }
parent spir 8 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton