With the said, you can do exhaustive pattern matching in TypeScript! https://github.com/gvergnaud/ts-pattern
With the said, you can do exhaustive pattern matching in TypeScript! https://github.com/gvergnaud/ts-pattern
function exhaustive(witness: never): never {
return witness
}
https://www.typescriptlang.org/play/?#code/FAFwngDgpgBAKgZQB...[0]: https://docs.python.org/3/library/typing.html#typing.assert_...
default:
matched satisfies never
throw new Error(...)
You don't even need a function.If you perfer using the same language for both frontend and backend work, yet would like to have one more semantically rich than TypeScript, consider Scala.
For the frontend, ScalaJS[0].
For the backend, Scala[1].
https://www.typescriptlang.org/play/?jsx=4#code/JYWwDg9gTgLg...
I guess the library is slightly nicer, arguably, but I don't think it's worth the external dependency and added complexity.
On the other hand, at least I get an excuse to write native addons.
If it wasn't for the projects that require Next.js I would never bother with Node.
Yes, you can do it via an assert never in a switch. That isn't pattern matching. That's an exhaustive switch enforced at compile time
Which is nice, but again, it's not pattern matching.