Which is why WebAssembly is the right answer.
Which one?
What does it matter to the user whether they get a runtime or a "compile time" error in their invisible devtools console? To them, the page simply doesn't work.
Static languages make sense when compilation happens at dev-time, where the actual devs can respond to the diagnostics. So it's far better to develop in a statically typed language, compile it ahead of time and ship that to the user. Which is exactly what people do now with wasm.
Also there's TS if you really want it