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
functiontest(x: unknown){if(typeofx==="string"||x===0){xif(x==="hello"||x===0){x}}if(check1(x)){xif(check2(x)){x}}}functioncheck1(x: unknown): x is (string|0){returntypeofx==="string"||x===0;}functioncheck2(x: unknown): x is ("hello"|0){returnx==="hello"||x===0;}
π Actual behavior
In the first set of nested scopes, typeof x is narrowed to string | 0 by the first if, and then "hello" | 0 by the second if. This behavior is correct.
In the second set of nested scopes, typeof x is narrowed to string | 0 by the first if, but is narrowed to 0 by the second if.
π Expected behavior
"hello" is a valid part of the subset of string, and should be included in the union type. The types derived from these two methods should be identical.
The text was updated successfully, but these errors were encountered:
Bug Report
π Search Terms
predicate, discrimination
π Version & Regression Information
β― Playground Link
Playground link
π» Code
π Actual behavior
In the first set of nested scopes,
typeof x
is narrowed tostring | 0
by the firstif
, and then"hello" | 0
by the second if. This behavior is correct.In the second set of nested scopes,
typeof x
is narrowed tostring | 0
by the firstif
, but is narrowed to0
by the second if.π Expected behavior
"hello"
is a valid part of the subset ofstring
, and should be included in the union type. The types derived from these two methods should be identical.The text was updated successfully, but these errors were encountered: