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
Verified using the playground with versions 3.3.3 through 4.4.4. Also tried nightly. I reviewed the common-bugs-that-arent-bugs comment for similar issues.
This is the behavior in every version I tried, and I reviewed the FAQ for entries about type narrowing / guarding (I skimmed the whole page.)
typeA={foo: string;}typeB=A&{bar : string;}declareconstbinding: A|B;// type is `A` but was expected to be `A | B`constsecondBinding=true ? binding : binding;if('bar'insecondBinding){secondBinding.bar;}
🙁 Actual behavior
binding has type A | B and was assigned to secondBinding. secondBinding has type A, but its type should've been inferred as the same type: A | B.
🙂 Expected behavior
secondBinding should have the same type as binding because it's assigned that way.
The text was updated successfully, but these errors were encountered:
Bug Report
🔎 Search Terms
ternary union narrow
🕗 Version & Regression Information
Verified using the playground with versions 3.3.3 through 4.4.4. Also tried nightly. I reviewed the common-bugs-that-arent-bugs comment for similar issues.
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
binding
has typeA | B
and was assigned tosecondBinding
.secondBinding
has typeA
, but its type should've been inferred as the same type:A | B
.🙂 Expected behavior
secondBinding
should have the same type asbinding
because it's assigned that way.The text was updated successfully, but these errors were encountered: