When attempting to compile the following code:
const value = "20"
const x : string | never = "10" === value ? throw Error("bad things") : "hello"
An error is encountered on throw
- expression expected
. One way to resolve this issue is by using an inline method invoked in place, although it may not look very clean. (
(() => {throw Error("bad things")})()
)
Why is it not acceptable to use throw in a branch of the ternary operator? Are there alternative syntax options that could work, or perhaps certain compile settings that I am overlooking?
It also seems that throw does not function properly without curly brackets in the function body, as shown in the workaround, (
(() => throw Error("bad things"))()
).