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
{{ message }}
Repository navigation
Contextually type the rightmost operand of comma operators and logical 'AND's #6199
&& is probably important since we use it's type in narrowing. Also i think its required to support the "short circuiting as ternary" pattern - if ("foo" === a && "foo" || "bar"). If the && doesn't get contextually typed here, I think we get string | "bar" for the rhs type, rather than "foo" | "bar".
Maybe? I'm just pretty sure the rhs operand of && should get contextually typed, mostly so you get consistent results with narrowing within/involving compound binary logic. In my example above I'm pretty sure I want the type of the RHS expression to be contextually typed as "foo"|"bar" rather than as string because this matches how a functionally equivalent ternary would have worked. I think.
So my point is that if in the statement if ("foo" === a ? "foo" : "bar") the RHS has type "foo" | "bar", the RHS of the statement if ("foo" === a && "foo" || "bar") should be the same. Mostly since if we plan to disallow if ("foo" === a ? "baz" : "bar") (as neither "baz" nor "bar" are assignable to type "foo"), it follows that if ("foo" === a && "baz" || "bar") should be the same type error by extension, since the expression is equivalent.
Wesley Wigham (@weswigham) Just to clarify, did you mean to parenthesize the conditional? In other words, by "foo" === a ? "foo" : "bar" you meant "foo" === (a ? "foo" : "bar").
Activity
weswigham commentedon Dec 22, 2015
&&is probably important since we use it's type in narrowing. Also i think its required to support the "short circuiting as ternary" pattern -if ("foo" === a && "foo" || "bar"). If the&&doesn't get contextually typed here, I think we getstring | "bar"for the rhs type, rather than"foo" | "bar".DanielRosenwasser commentedon Dec 22, 2015
You'd just get
stringactually. Did you meanif ("foo" === a && a || "bar")with your type narrowing change applied?weswigham commentedon Dec 23, 2015
Maybe? I'm just pretty sure the rhs operand of
&&should get contextually typed, mostly so you get consistent results with narrowing within/involving compound binary logic. In my example above I'm pretty sure I want the type of the RHS expression to be contextually typed as"foo"|"bar"rather than asstringbecause this matches how a functionally equivalent ternary would have worked. I think.weswigham commentedon Jan 3, 2016
So my point is that if in the statement
if ("foo" === a ? "foo" : "bar")the RHS has type"foo" | "bar", the RHS of the statementif ("foo" === a && "foo" || "bar")should be the same. Mostly since if we plan to disallowif ("foo" === a ? "baz" : "bar")(as neither"baz"nor"bar"are assignable to type"foo"), it follows thatif ("foo" === a && "baz" || "bar")should be the same type error by extension, since the expression is equivalent.DanielRosenwasser commentedon Jan 3, 2016
Wesley Wigham (@weswigham) Just to clarify, did you mean to parenthesize the conditional? In other words, by
"foo" === a ? "foo" : "bar"you meant"foo" === (a ? "foo" : "bar").weswigham commentedon Jan 3, 2016
Aye. Parenthesis.
On Sun, Jan 3, 2016, 12:30 PM Daniel Rosenwasser notifications@github.com
wrote:
DanielRosenwasser commentedon Jan 5, 2016
I put out a fix for this with #6355.