I try to compile:
const value = "20"
const x : string | never = "10" === value ? throw Error("bad things") : "hello"
... and get an error on throw
- expression expected
. I can resolve this using an inline method invoked in place, but that does not look nice. ((() => {throw Error("bad things"})()
)
Why is not OK to throw in a branch of the ternary operator? Or is there another syntax that works, perhaps compile options I'm missing?
Throw does not seem to work without curly brackets in the function body either, in the work-around, ((() => throw Error("bad things")()
).