Does TypeScript have a way to force a crash on type error?

In Elixir, there is a set of compile-time errors (e.g. misspelling a variable) that will cause the process to crash, forcing you to fix them.

In TypeScript, the compile-time error will be emitted but won’t crash the app.

I was wondering if there is a way to roughly replicate the behaviour of Elixir’s compiler via TypeScript’s config. (I’ve already glanced through its compilerOptions.)

Could you please tell how you managed to create a runtime type-error in TypeScript?

It should simply not happen.

Also in elixir, misspelling a variable will fail at compile time, not runtime, and it is not even a type error…

So could you please elaborate on this?

1 Like

Sure.

So I guess what you’re saying is the blank screen plus error message is a frontend compiler error.

What I’m saying is rather than seeing that on the browser, I’d like to see the compiler fail to run, if say I misspell something (which is the behaviour of Elixir’s compiler).

In this way, it speeds things up a bit and makes for a dev experience I’d prefer.

Not saying this is the way for all–just wondering if there is a way to get this behaviour through a compilerOption


P.S. Found this: https://github.com/smooth-code/error-overlay-webpack-plugin/blob/master/README.md

I regularly do not care for things happening in the browser.

For me a compile error are those, that essentially fail my build pipeline and therefore make it impossible to get an artifact to deploy.

Runtime errors are those that are visible to the customer, because the software crashes after the deployment/delivery.

And if I have this code:

defmodule M do
  def f() do
    bar = "bar"
    IO.puts(bat)
  end
end

It will give me 2 warnings (“variable bat undefined, expanding to bat()" and "bar is unused”), also I do see a compilation error because bat/0 is undefined.

So there is a compile time error on misspelled names in elixir, still those are not type errors.

1 Like