You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
That's a syntax error; just use x ?? (throw "error").
The underlying reason is that ?? requires an operand which is a <logicalOrExpression>, but <throwExpression> is derived directly from <expression> (so it's "more general" than <logicalOrExpression>).
The precedence of throw is such that this does not work. See also #24891.
The throw operator binds weakly. It means that throw foo + bar means throw (foo + bar) and not (throw foo) + bar, because the latter is meaningless anyway.
(In hindsight, that might not have been the best choice, because it prevents things like foo ?? throw bar, and you would not write throw foo + bar anyway, and it's confusing that it works differently from await).
As Erik has said, you have to wrap your throw in parentheses.
Expression
x ?? expr
, intuitively, should be equivalent tox != null ? x : expr
, but it is not.Is it so by design?
The text was updated successfully, but these errors were encountered: